Search hibernate entities by prototype

前端 未结 2 1586
无人及你
无人及你 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条回答
  •  猫巷女王i
    2021-01-26 20:24

    So you're looking for a prototype? Hibernate has a handy Example criteria just for this, so if you don't mind tying yourself to the Hibernate API, try this example from the docs:

    Cat cat = new Cat();
    cat.setSex('F');
    cat.setColor(Color.BLACK);
    List results = session.createCriteria(Cat.class)
        .add( Example.create(cat) )
        .list();
    

    It specifically says:

    Version properties, identifiers and associations are ignored. By default, null valued properties are excluded.

    Which is just what you appear to want.

提交回复
热议问题