Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jacky S Zhang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic