• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create a Sub Query in a Criteria Query

 
Kunal Bhatia
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Iam facing a problem in creating a sub query within a Criteria Query.Please help:

Sql Query

Select salary from employee_table where

name = Parameter.[name]
age = Parameter.[age]
dateofbirth = Select Max(dateofbirth) from employee_table
where name = Parameter.[name],
age = Parameter.[age],
dateofbirth < = Parameter.[dateofbirth]

Please help as iam stuck on dis code
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do that by using the 'DetachedCriteria' in hibernate

for e.g.-



since you are passing 'data' as a parameter, so what you do
1)create an object of detachedcriteria first,
2)add the expression,
3) and finally set the projection(in the 2nd line above code) using the 'max()'

refer the link below:-
Hibernate Criteria Queries

enjoy buddy .... :-)
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do Your Homework
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic