How to implement a Spring Data repository for a @MappedSuperclass

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

Leave a Comment

File not found.