Search hibernate entities by prototype

前端 未结 2 1582
无人及你
无人及你 2021-01-26 20:06

I\'ve got JPA entity class like this:

@Entity
@Table(name = \"person\")
public class Person {
   @Id
   private Long id;
   private String lastName;
   private S         


        
2条回答
  •  孤街浪徒
    2021-01-26 20:40

    You should look into Hibernate Criteria. You can stack restrictions as such:

    List cats = sess.createCriteria(Cat.class)
        .add( Restrictions.like("name", "Fritz%") )
        .add( Restrictions.or(
            Restrictions.eq( "age", new Integer(0) ),
            Restrictions.isNull("age")
        ) )
        .list();
    

    Restrictions refer to annotated variables in the class. Take a look at the documentation.

提交回复
热议问题