Spring Data JPA find by embedded object property

前端 未结 4 1022
小蘑菇
小蘑菇 2020-12-02 09:29

I want to write a Spring Data JPA repository interface method signature that will let me find entities with a property of an embedded object in that entity. Does anyone know

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 09:56

    If you are using BookId as an combined primary key, then remember to change your interface from:

    public interface QueuedBookRepo extends JpaRepository {
    

    to:

    public interface QueuedBookRepo extends JpaRepository {
    

    And change the annotation @Embedded to @EmbeddedId, in your QueuedBook class like this:

    public class QueuedBook implements Serializable {
    
    @EmbeddedId
    @NotNull
    private BookId bookId;
    
    ...
    

提交回复
热议问题