In Spring Data JPA trying to use interface projection technique:
interface DocInfoShort {
var docTypeId: Int
}
And my DAO:
public interface DocRepository extends JpaRepository<Doc, Long> {
@Query("select sum(cast(doc.isSent AS int)) as docTypeId" +
" from Doc doc group by docTypeId", nativeQuery = true)
fun someQuery(): List<DocInfoShort>
}
but it is not working:
could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
How can i fix it.
Just make DocInfoShort
a class with a proper constructor and use the constructor syntax of JPQL in the query annotation:
@Query("select new full.package.name.DocInfoShort(sum(cast(doc.isSent AS int)))" +
"from Doc doc group by docTypeId")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.