Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner query in hibernate

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have following query




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

Thanks
 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic