I've implemented a custom JPA repository as :
public class BaseEntity{...}
public class DerivedEntity extends BaseEntity{...}
@NoRepositoryBean
public interface BaseRepository<T extends BaseEntity> extends JpaRepository<T, ID>{
//some common method
}
@Repository
public interface DerivedRepository extends BaseRepository<DerivedEntity>{
}
Now, I want created a common data-service :
public class CommonService{
private BaseRepository<? extends BaseEntity> baseRepository;
//wants to use common method by passing derivedRepository
public CommonService(BaseRepository<? extends BaseEntity> derivedRepository) {
this.baseRepository=derivedRepository;
}
}
Now,Somewhere in the code I want to use save method:
public void foo(BaseEntity entity ) {
baseRepository.save(entity);
...
...
}
I'm getting compile time error:
can not resolve save
How to resolve this issue and design ? Whats the best way to design a common data service by using common data repository ?