質問

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