-->
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.  [ 7 posts ] 
Author Message
 Post subject: Filtering objects if child has a null property
PostPosted: Sun Sep 10, 2006 5:33 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
Hibernate version: 3.2.0 rc2

Mapping documents:
<hibernate-mapping>
<class name="com.softbare.vo.Prescription" table="prescription">
<id name="id" column="id" unsaved-value="null">
<generator class="increment"/>
</id>
<set name="treatments" table="treatment" inverse="true" cascade="save-update">
<key column="prescription_id"/>
<one-to-many class="com.softbare.vo.Treatment"/>
</set>
</class>
</hibernate-mapping>

Code to fetch prescriptions where the treatment have a null property
public List findTreatedPrescriptions() {
/*
SELECT p.id, p.date
FROM prescription p, treatment t
WHERE p.id = t.id
AND t.attest_id = null;
*/
String hqlQuery = "select distinct p from Prescription p, Treatment t " +
"inner join t.prescription " +
"where t.attest is null";

HibernateTemplate hibernateTemplate = getHibernateTemplate();
return hibernateTemplate.find(hqlQuery);
}

Problem
I get a List of prescriptions back; but each Prescription in the list contains all treatments where I only want to treatments who have a null property. Namely where the attest is null

What's the best way to achieve this kind of functionality?? filters? lazy=extra, ... ????

Please help me out here!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 3:54 am 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
Nobody that can help me out here??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 7:44 am 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
Couldn't be that hard?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 8:04 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:44 am
Posts: 27
<set name="treatments" table="treatment" inverse="true" cascade="save-update" where="t.attest_id = null">
<key column="prescription_id"/>
<one-to-many class="com.softbare.vo.Treatment"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 16, 2006 1:03 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
This solution didn't work... Can someone please point me out with a valid approach?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 8:24 am 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
could someone provide me with a descent answer, please??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 9:03 am 
Newbie

Joined: Tue Sep 12, 2006 5:47 am
Posts: 4
select p.* from Prescription p " +
"inner join Treatment t " +
"on p.id = t.prescription_id " +
"where t.attest is null"

Try this query.. might help you out


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