2

I have two tables in my Database, Tuser and TCompany,
where

Tuser : id | name | email  
Tcompany : id | companyName | userId  

where userId is foregn key of Tuser table.

I have written a query to get all users whose name start with a

Criteria criteria = ctx.getSession().createCriteria(Tuser.class);  
criteria.add(Restrictions.like("name", "a%"));  
List res = criteria.list()

Now i need to get all users who do not belong to a company.
In sql, we can use sub-queries, but i am getting stuck as to how it is done using criteria?

Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
Abhishek
  • 1,999
  • 5
  • 26
  • 52
  • This question might address it: http://stackoverflow.com/questions/2602490/hibernate-criteria-perform-join-in-subquery-detachedcriteria?rq=1 – Marvo Feb 28 '13 at 19:24
  • 1
    http://docs.jboss.org/hibernate/core/3.6/javadocs/org/hibernate/criterion/Subqueries.html is a factory of subqueries. Each subquery is a criterion that can be added like any other criterion to your criteria. – JB Nizet Feb 28 '13 at 19:44

0 Answers0