Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic