This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate one-to-many, one-to-one association not selecting records without children Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate one-to-many, one-to-one association not selecting records without children" Watch "Hibernate one-to-many, one-to-one association not selecting records without children" New topic
Author

Hibernate one-to-many, one-to-one association not selecting records without children

Jacky S Zhang
Greenhorn

Joined: Jul 21, 2010
Posts: 13
I have 3 tables:

table1
table2
table3

table1 to table2 is one-to-many
table2 to table3 is one-to-one

I created following query:



and



If records in table1 has children(in table2), records are selected, but if records in table1 don't have children, they are not selected. In the log, the SQL it generated is like:

select * from table1 left outer join table2 (on .....) inner join table3 (on ....)

was wondering if it's caused by the "inner join" to table3 so those records don't have children in table2 got dropped?

How do I make those records not dropped? I was hoping the generated SQL like:

select * from table1 left outer join table2 (on .....) left outer join table3 (on ....)

Any idea?


joy b chakravarty
Ranch Hand

Joined: May 16, 2011
Posts: 62

table1 to table2 is one-to-many
table2 to table3 is one-to-one


Looks like you want records from table 3 when you don't have any records in table 2 (no children).
This would only be possible when you have some sort of direct relationship between table1 and table 3 (probably one-to-many).


Cheers, Joy [SCJP 1.4, SCBCD 5.0]
get high on alcohol, algorithm or both
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate one-to-many, one-to-one association not selecting records without children