-->
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.  [ 2 posts ] 
Author Message
 Post subject: Query DB table where an attribute is null
PostPosted: Mon Apr 30, 2007 11:25 am 
Newbie

Joined: Mon Apr 30, 2007 11:13 am
Posts: 1
Hi,
I have a table which is a self-referencing table. The parent_id attribute is null if the record has no parent.

I need to get such records with parent_id as null using restrictions\expression creiteria queries.

result = session.createCriteria(Template.class)
.add( Expression.eq("template", null )).list();

but I do not get the desired result.

The parent_id column present in the Database is referencing ID (the primary key) of the same table. The parent_id is null if the record has no parent.

Thanks,
Raj

P.S->
<hibernate-mapping>
<class name="autochecklist.Template" table="template" catalog="comp">
<comment></comment>
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<many-to-one name="options" class="autochecklist.Options" fetch="select">
<column name="optionsId">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="template" class="autochecklist.Template" fetch="select">
<column name="parent_id">
<comment></comment>
</column>
</many-to-one>
<property name="label" type="string">
<column name="label" length="200" not-null="true">
<comment></comment>
</column>
</property>
<property name="type" type="string">
<column name="type" length="45" not-null="true">
<comment></comment>
</column>
</property>
<property name="hidden" type="boolean">
<column name="hidden" not-null="true">
<comment></comment>
</column>
</property>
<set name="templates" inverse="true">
<key>
<column name="parent_id">
<comment></comment>
</column>
</key>
<one-to-many class="autochecklist.Template" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Query DB table where an attribute is null
PostPosted: Mon Apr 30, 2007 12:49 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
quicksilverm26 wrote:
result = session.createCriteria(Template.class)
.add( Expression.eq("template", null )).list();


Try
Code:
result = session.createCriteria(Template.class, "parent")
            .add( Restrictions.isNull("parent.template" )).list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.