aspose file tools*
The moose likes Object Relational Mapping and the fly likes Using JOINs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Using JOINs" Watch "Using JOINs" New topic
Author

Using JOINs

Himanshu
Greenhorn

Joined: Nov 05, 2008
Posts: 5
Hi,

To use JOINs (left, inner), document says that it is mandatory to have proper associations in HBM files, like <many-to-one>, <one-to-one> etc.

Lets say I want to keep HBMs independent, i.e., I don't want to define any association. Is it still possible to write HQLs wherein I map 2-3 tables, may be using inner/outer join, to retrieve results or I should use SQL in that case?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"geminine", please check your private messages.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


To use JOINs (left, inner), document says that it is mandatory to have proper associations in HBM files, like <many-to-one>, <one-to-one> etc.

Assuming we are talking about Hibernate here, their documentation does not say it is mandatory to map associations in the mapping files.


Lets say I want to keep HBMs independent, i.e., I don't want to define any association. Is it still possible to write HQLs wherein I map 2-3 tables, may be using inner/outer join, to retrieve results or I should use SQL in that case?


I can't think of a reason why you would want to do this (especially as queries written in HQL will largely ignore the association mapping in favour of an explicit join) - what is it you are trying to achieve? But yes, you can map the foreign key as an property rather than an association.
Himanshu
Greenhorn

Joined: Nov 05, 2008
Posts: 5
I have 2 tables - TableA & TableB. TableB contains reference to TableA. Now to execute a left join or inner join query, I need to define <many-to-one> association in TableB.hbm.xml and may be a <set> / <one-to-many> association in TableA.hbm.xml.

If I don't define associations, and simply define foreign key in TableB, I'm not able to execute HQL - select * from TableADO a left join TableBDO b on a.key = b.key

Hope you understood my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using JOINs