Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JOINs

 
Himanshu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"geminine", please check your private messages.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic