This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using JOINs
 
Similar Threads
disable overflow to inner div element if outer div uses overflow hidden
sql server to oracle(sql plus)
inserts into join tables
Nested Tables and Colspan attribute
Using subselect tag or creating a view