JPA: How to get entity based on field value other than ID?

前端 未结 15 947
时光说笑
时光说笑 2020-12-04 21:08

In JPA (Hibernate), when we automatically generate the ID field, it is assumed that the user has no knowledge about this key. So, when obtaining the entity, user would query

15条回答
  •  悲&欢浪女
    2020-12-04 21:42

    Refer - Spring docs for query methods

    We can add methods in Spring Jpa by passing diff params in methods like:
    List findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);

    // Enabling static ORDER BY for a query 
    
    List findByLastnameOrderByFirstnameAsc(String lastname);
    

提交回复
热议问题