0
I implemented methods into one Repository
for all my children repositories have the same methods. Download the code of how I implemented a Repository
Personalized
This is the interface:
@NoRepositoryBean
public interface BaseMyRepository<T, ID extends Serializable> extends JpaRepository<T, ID>{
List<T> findCustomNativeQuery(String sqlQuery);
}
This is the implementation of the class:
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 is 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> {
}