wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes inner query in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "inner query in hibernate" Watch "inner query in hibernate" New topic
Author

inner query in hibernate

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 300
Hi

I have following query




How can i do this using Criteria Api.Please tell me.

Thanks
pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 300
i try do this in hql by this way :



But i am getting exception



Please tell me where is the error.
Bogdan Baraila
Ranch Hand

Joined: May 23, 2011
Posts: 43
You can try doing this in 2 parts.
Obtain your rempim_tb by using the hql ("from rempim_tb as rem where rem.mpim_emp_no=' "+your_number+" ' ")
And then use the remprim in the second query: ("from rebrcd_tb as reb where reb.brcd_part_no <......).
Also you need to use you're java classes in the hql and it would be easier if you also post you java classes for this objects to better understand what you want.
pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 300
Hi can you tell me how to write the second query as you mentioned in reply

And then use the remprim in the second query: ("from rebrcd_tb as reb where reb.brcd_part_no <......).



My classes are






Bogdan Baraila
Ranch Hand

Joined: May 23, 2011
Posts: 43
Let's say that you have saved the object from the first query in: rempim.
Then in the second query you need to do: ("from BarCodeEntry as bCode where bCode.BRCD_PART_NO > ' "+rempim.MPIM_PART_NO_FRM+" ' and bCode.BRCD_PART_NO < ' " + rempim.MPIM_PART_NO_TO + " ' ")
pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 300
Hi Bogdan,
Thanks its work what you said.But i have one question.
By using your logic it will generate 2 sql .So can i use plain sql .

Tell me which one is better and why.


Thanks
Bogdan Baraila
Ranch Hand

Joined: May 23, 2011
Posts: 43
you also have a subselect in your sql querry so the diffrence is not so big. you can also use native sql, search for something like 'createSQLQuery'.
 
Don't get me started about those stupid light bulbs.
 
subject: inner query in hibernate
 
Similar Threads
Use substr function in Criteria
org.hibernate.exception.SQLGrammarException: could not execute query
inner query in hibernate
Problem with query
Invalid column name while calling store procedure