문제

I am working on Hibernate I have Emp table but I want to fetch the data like this

String query = "Select * from emp where ename='bhanu' or ename='hari' or ename='balu'";

How can I do this by using Hibernate Criteria API?

도움이 되었습니까?

해결책

Why do you need an or condition here? Can you not do an IN query instead? Also, i would suggest you look up the hibernate documentation for the criteria query API. It is pretty basic and will help you understand and structure your DB layer.

Here is how you do it using the Criteria API.

List employees = session.createCriteria(Emp.class)
    .add(Restrictions.or(
Restrictions.eq("ename", "bhanu") ,Restrictions.eq("ename", "hari") ,Restrictions.eq("ename", "balu") 
    ) )
    .list();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top