Subqueries in HQL by R4R Team

For databases that support subselects, Hibernate supports subqueries within queries. A subquery must be surrounded by parentheses (often by an SQL aggregate function call). 

Even correlated subqueries (subqueries that refer to an alias in the outer query) are allowed.

1. from Student as fatcat where fatcat.weight > 
(
    select avg(student.weight) from DomesticStudent student
)

2. from Domesticstudent as student where student.name = some 
(
    select name.nickName from Name as name
)

3. from Student as student where not exists 
(
    from Student as mate where mate.mate = cat
)

4. from DomesticStudent as student where student.name not in 
select name.nickName from Name as name
)

5. select student.id, (select max(kit.weight) from student.kitten kit) from Student as student

We have to remember that HQL subqueries can occur only in the select or where clauses. and subqueries can also utilize row value constructor syntax
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!