These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Select objects with null property
PostPosted: Tue Feb 20, 2007 4:04 pm 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Hi everybody

How can i select the objects where a property is null? I have a Category table:

* Id, int
* Name, varchar
* Parent, int

The parent field makes the relation between the present category and its parent, if it has one. If the category is a root category that value should be null. So how can i select all categories that have not parent, i.e. those rows where parent is null?

thanks in advance.

Code:
@Entity()
@Table(name = "Categories")
public class Category implements Serializable {
   
    @Id
    @Column(name = "id")
    private String id;
   
    @Column(name = "name")
    private String name;
       
    @OneToMany(mappedBy="parent")
    private List<Category> children;
   
    @ManyToOne
    @JoinColumn(name="parent")
    @NotFound(action=NotFoundAction.IGNORE)
    private Category parent;
   
}


Hibernate version: 3.2

Name and version of the database you are using: HSQLDB, 1.8.0.7


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 7:18 pm 
Newbie

Joined: Tue Feb 20, 2007 10:19 am
Posts: 4
Use this HQL query:
Code:
from Category as c where c.parent is null

You can read more about the Hibernate Query Language at http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 4:18 am 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
I had just found that answer in the page you say. Anyway, thank you very much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.