aspose file tools*
The moose likes Object Relational Mapping and the fly likes [Hibernate] Join without FK Relationship using Criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Hibernate] Join without FK Relationship using Criteria" Watch "[Hibernate] Join without FK Relationship using Criteria" New topic
Author

[Hibernate] Join without FK Relationship using Criteria

Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

I have this problem to perform a join between two tables when there is no FK relationship at all. I've googled it and spent countless hours with no luck

Suppose I have these two entities.


With HQL, I can simply do this.


Is there a way to achieve the same result using Query by Criteria? And I need to get the properties from both entities. So, using in subquery will not work at all.

Thanks in advance.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I think your only option is to do it as two queries and join in code. or just use HQL.

I would ask however, why are you trying to treat unrelated data as if it were related? If Person has an addressID why does it not have a proper association with the Address table? Hibernate tends not to work well when you start trying to do stuff that kind of goes against the logic of relational data. If these entities are really related and you haven't enforced this relationship in your data model it is oly a matter of time before the data becomes corrupt.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Thanks for your reply.

It's just for my curiosity because a friend of mine asked me this and it sometimes happen when we deal with legacy apps. Btw, wouldn't the performance be rather bad if we perform the join in code as opposed to in HQL?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Hibernate] Join without FK Relationship using Criteria