wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes complex query in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "complex query in hibernate" Watch "complex query in hibernate" New topic
Author

complex query in hibernate

Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

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

Joined: Jul 20, 2005
Posts: 9343
    
111

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.


[My Blog] [JavaRanch Journal]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: complex query in hibernate
 
Similar Threads
Seeking help on a complex SQL I reckon, wish get a simple one from answer
any good hql query for this scenario?
Getting slow to load the data
How to access Stored Procedure
Hibernate with native SQL issue