简体   繁体   中英

How to return custom object using projection in Spring Data Jpa?

I am trying to return custom object from spring data jpa - native query

Here's what I've done so far according to this How to return a custom object from a Spring Data JPA GROUP BY query

I should be able to create query like this:

Query(nativeQuery = true, value = "select sc.case_type as caseType, sc.revision as revision from smart_casemodel sc minus select s.casetype, s.revision from smart_case s")
List<CtRevOnly> findNotUsedCasemodels();

I declared projection Interface

public interface CtRevOnly {
    String getCaseType();
    String getRevision();
}

Then simply call it

caseModelRepository.findNotUsedCasemodels();

however I get an exception

javax.persistence.PersistenceException: org.hibernate.MappingException: Unknown entity: javax.persistence.Tuple

Any idea what am I doing wrong ?

For anyone running into the same problem
I am using Hibernate 5.1.2.Final

I guess there's a bug and I need to upgrade to hibernate 5.2.11 to make it work See this link

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM