• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

complex query in hibernate

 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for writing a complex query in hibernate. Can anybody provide me useful tutorial.

The scenario is:
1> I have to get the list of data(ie.object) from 1 table using where clause. and then for eve

2> Then for every item in the list I have to get the list of data(ie. object) from 2nd table.

Both tables are connected by foreign key relationship.

Is it possible to write a single query instead of 2 queries so that I can get desired result from second table directly.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess, you can do the following:

Have an hibernate object(HO) XyzHO mapped to table XYZ and an hibernate object AbcHO mapped to table ABC.

Your XyzHO would look like:

public class XyzHO {

....
//set of AbcHO objects
Set abcHOs;

}


public class AbcHO {

...
//reference to the XyzHO
XyzHO xyzHO;

}

You would then map these two objects to the tables using, hbm files.

Then your query would look something like:

"from XyzHO where place your where clause"

This would return you a list of XyzHO objects and each XyzHO object would contain a collection of AbcHO objects.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic