I have an abstract entity annotated with @MappedSuperclass
:
@MappedSuperclass
public abstract class BaseEntity {
public abstract T getId();
public abstract void setId(T id);
}
Then I inherit my Entities from it, defining their id in each one:
@Entity
public class EntityA {
@Id
private int id;
// ....
}
@Entity
public class EntityB {
@Id
private long id;
// ....
}
Now I want to create a generic JpaRepository that accepts any class that extends from my Base Entity:
public interface BaseRepository<T extends BaseEntity, ID extends Serializable> extends JpaRepository<T, ID> {
}
But Spring trows an exception saying BaseEntity
has no ID:
java.lang.IllegalArgumentException: This class [BaseEntity] does not define an IdClass
Please, check Plog's comments in his answer. I could solve it injecting each repository type in service's contructor