-->
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.  [ 4 posts ] 
Author Message
 Post subject: left outer join problem
PostPosted: Tue Jun 20, 2006 8:18 am 
Newbie

Joined: Sat Apr 01, 2006 2:23 pm
Posts: 6
Hibernate version: 3.1.rc2

Name and version of the database you are using:Oracle 9.0.2

I have 2 classes: Father, Son linked with OneToMany.
Now I perform this HQL:
"SELECT s FROM Son s LEFT JOIN FETCH s.father WHERE s.id = 1"

The tables are as followed:
Son:
id father
-- -------
1

Father
id
--
1

now the query works, and I get a Son entity, great.
But what happens when I want to approach the father property? (something like "System.out.println(s.getFather())" ).
If I will try to get the property I get an exception because the Entity with that key doesn't exist.
But all I want is to get an empty value (a null), I don't want the hibernate to run a new select, because I already know there aren't any values in there (because I did a left join).

Is it a bug or is there some workaround?


Top
 Profile  
 
 Post subject: you need to say lazy="true"
PostPosted: Tue Jun 20, 2006 3:05 pm 
Newbie

Joined: Wed Apr 26, 2006 2:43 pm
Posts: 6
Location: Bangalore
Hi

there are two ways either u specify lazy="true" in mapping document or specify FetchMode Lazy in query it self.



Regards
Arpit Patel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 1:02 am 
Newbie

Joined: Thu Mar 17, 2005 9:38 am
Posts: 1
SELECT s FROM Son s LEFT JOIN FETCH s.father WHERE s.id = 1

remove the 'FETCH' and where clause

SELECT s FROM Son s LEFT JOIN s.father


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 6:07 am 
Newbie

Joined: Sat Apr 01, 2006 2:23 pm
Posts: 6
Arpit Patel:
it already is lazy, still not working.

DraculaCwg:
I need that where clause, and removing the fetch doesn't help.

any other ideas?


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