• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JOINs

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"geminine", please check your private messages.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic