I've implemented methods on a Repository
so all my child repositories have the same methods. Lowers the code of how I implemented a% custom%
This is the interface:
@NoRepositoryBean
public interface BaseMyRepository<T, ID extends Serializable> extends JpaRepository<T, ID>{
List<T> findCustomNativeQuery(String sqlQuery);
}
This is the class implementation:
public class BaseMyRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements BaseMyRepository<T, ID>{
private final EntityManager entityManager;
public BaseMyRepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager){
super(entityInformation, entityManager);
this.entityManager = entityManager;
}
@Transactional
@Override
public List<T> findCustomNativeQuery(String sqlQuery) {
List<T> lista = entityManager.createNativeQuery(sqlQuery, this.getDomainClass()).getResultList();
return lista;
}
}
This is my repository ( Repository
):
public interface MyRepository extends BaseMyRepository<SmaempreEntity, Integer>{
}
Now I need to know if it's possible to do the code below. Below I have exemplified what I need.
@Service
@Transactional
public class MyBaseService<R extends BaseMyRepository, E> {
@Autowired
private R;
public List<E> findAll() {
return R.findAll();
}
public List<E> findCustomNativeQuery(String sqlQuery) {
return R.findCustomNativeQuery(sqlQuery);
}
}
public class MyService extends MyBaseService<MyRepository, MyEntity> {
}