method with a native query like this on MyClassRepository:
@Query("SELECT id + 1 AS code, * FROM mytable")
List<MyClass> findAll();
And then, I need to apply some optional filters with criteria builder
myClassRepository.findAll(new Specification<MyClass>{
@Override
public Predicate toPredicate(Root<MyClass> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { BUNCH_OF_CODE; }
});
The error I get is:
could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
@Query queries work on entities directly. You need to get the entities and then apply a mapping to convert into a DTO as you like
The problem is in your query. It has select "*", which already has a field "code" in it, which is fetched from table. And you add one more calculated field with same name "code". No surprise that you have a conflict. Try running that query against your db directly from db console
Обсуждают сегодня