2

I've a query like this. Which I don't know how to make it up in Hibernate criteria. I've done a lot of stuffs in hibernate criteria, but don't have any idea if the query is like below.

select employer.phoneNo, employee.phoneNo, lender.phoneNo 
from employer,employee,lender 
where employer.phoneNo='xxxxxxxx' 
or employee.phoneNo='xxxxxxxx' 
or lender.phoneNo='xxxxxxxx';

All the three Employer, Employee, Lender don't have any relationship with each other. The purpose of the query is to check whether the given phone number is exist even in any one of the table to prevent a new user registration with same phone number.

I know how to do it with SQLQuery sqlQuery = getSession().createSQLQuery(sql);, but is it possible in hibernate criteria?

Avidan
  • 1,431
  • 2
  • 20
  • 36
The Coder
  • 2,349
  • 5
  • 31
  • 55
  • 2
    No, it's not possible with Hibernate criteria. But why would you use Criteria for such a static query? Use HQL, that's what it's for. Criteria is useful to dynamically compose queries from multiple... criteria. – JB Nizet Apr 11 '15 at 14:19
  • 1
    @JBNizet , Thanks.. I'll stick with HQL.. – The Coder Apr 11 '15 at 14:28

0 Answers0