• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

So much on the Left Joins in Hibernate

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part I:
I recently adopted Hibernate and am still confused when it comes to creating the mapping files. Whether to include sets of children in parent table objects and one-to-many relationship definitions in the parent table mapping file or define parent table entries in child objects with many-to-one relationship defined in the child table mapping file or adopt both ways as per the requirements.

I can either write HQL left join queries either as

in the first case as we mention kittens as a set in the object file and the relationship between cat and kittens as one-to-many from cat to kittens.

In the second case, which I have always been interested in

in the second case, which seems to be not possible for some reason. So does this mean we cannot left join un-related tables or rather when no mapping is defined in the mapping file to define a relationship?

I am not sure if the code has correct syntax in a left join of a parent table object with its child object though.


Part II
I have been writing HQL queries in hibernate to get all the tables' columns' data in one single query just like any other JDBC query. Writing LEFT JOINS on many tables was harder and I was not sure if I was doing it right anyways. Could any body suggest a better way to modify the object and mapping file to LEFT JOIN many tables please...

Lets say TableA->TableB->TableC<-TableD and TableA->TableE->TableF where -> indicates the parent to child relationships and I have to get data from all of these tables in one shot. I created a new object with fields and constructors to populate only those fields which are required. I see that the LEFT JOIN query is a little complicated as, I had to include TableB objects as a set in Table A and TableC objects as a set in TableB with a
and change the TableAObj mapping file to include TableB set as



However, things change when relating TableC and TableD this way. So I had to write them differently as

TableCObj has TableDObj field
and the TableCObj mapping file had to be written as:



And finally get all the populated objects in a single query as:



Is this the optimal way of creating objects whose fields populate different data from different columns of different tables?

Also is it ok to set any of the getter methods in these object files as follows:



Similary is it correct to include more logic in the setters method, say some field setter method that sets based on other fields as in



assuming they are already set by their setter methods??

[ March 25, 2008: Message edited by: Rama Krishna ]

[ March 25, 2008: Message edited by: Rama Krishna ]
[ March 25, 2008: Message edited by: Rama Krishna ]
 
mooooooo ..... tiny ad ....
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic