-->
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: left outer join fetch & where problem
PostPosted: Thu Aug 02, 2007 1:56 pm 
Newbie

Joined: Tue Jul 03, 2007 11:09 am
Posts: 14
HI,

For an example i have a table tree whose primary key is referenced in many rows of table fruits. To get all the available trees left outer joined with fruits with weight say 10 gms i need to write this query.

My Approach:

Code:
select trees
from
  trees left outer join fruits fr
where
  fr.weight=10


The problem is that the query fails when there is a tree with 1 fruit of wt equal to 1 gms.

What i require is All trees irrespective of fruits & if there are fruits of wt 10 grams associate them also.

kindly help.

Ravi C


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 11:10 pm 
Newbie

Joined: Tue Jul 03, 2007 11:09 am
Posts: 14
The documentation says that we cant use subselects in from clause. So how do we go about such cases?


Kindly help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 6:13 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
try this

from
trees t
left outer join t.fruits as fr
where
fr.weight=10

and in mapping of trees.hbm.xml
add this line :
<many-to-one name="fruits" class="fully qualified name of fruits class" column="trees_id" insert="false" update="false" />

and in Trees.java
add
private Fruits fruits; with its getter and setter.
you can put select clause also with its condition.

[rate, if helpful]

Thanks,
Gopal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 6:18 am 
Newbie

Joined: Tue Jul 03, 2007 11:09 am
Posts: 14
Hi,

The query does not work please look into the initial posts. The same query is written.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 6:23 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
ravi_eze1 wrote:
Hi,

The query does not work please look into the initial posts. The same query is written.


Check this once carefully,
This is different from your query. and I can assure you that This ll work correctly, If you applies it correctly.

Thanks,
Gopal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 6:41 am 
Newbie

Joined: Tue Jul 31, 2007 8:35 am
Posts: 3
gopal.knoah wrote:
ravi_eze1 wrote:
Hi,

The query does not work please look into the initial posts. The same query is written.


Check this once carefully,
This is different from your query. and I can assure you that This ll work correctly, If you applies it correctly.

Thanks,
Gopal


Hmm, maybe this isn't the answer they're looking for, in the original post.....

Quote:
What i require is All trees irrespective of fruits & if there are fruits of wt 10 grams associate them also.


Are they saying, the result set should be all trees, regardless of the weight of fruit, but also, if the weight of the fruit is 10 or greater then the related fruit entity should be populated too.

Sounds like a where clause controlling the fetch functionality? Don't know if that can be done?

Tom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 2:38 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Let me know what error are you getting ?

Thanks,
Gopal


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.