How to implement a Spring Data repository for a @MappedSuperclass

前端 未结 1 390
遇见更好的自我
遇见更好的自我 2020-12-14 08:08

I\'ve got a JPA @MappedSuperClass and an @Entity extending it:

@MappedSuperclass
public cl         


        
相关标签:
1条回答
  • 2020-12-14 08:31

    It's just a matter of annotating the abstract Repository as @NoRepositoryBean:

    @NoRepositoryBean
    public interface Dao<T extends BaseClass, E extends Serializable> extends
            CrudRepository<T, E> {
    
        Iterable<T> findByActive(Boolean active);
    
    }
    

    This way Spring relies on the underlying repository implementation to execute the findByActive method.

    Regarding to the annotation type restriction issue, it's not possible to declare an annotation restricted type. See the referenced answers below.

    See also:

    • Generic Spring Data JPA repository implementation to load data by class type
    • Annotations: restrict reference to classes with a annotation
    0 讨论(0)
提交回复
热议问题