Hi,
I am trying to migrate from Hibernate 5.0 to 5.2.
In Hibernate 5.0, we had a very complex query including several entities/tables.
Therefore, I used a combination of query.addScalar()-calls and a ResultTransformer:
Code:
SQLQuery sqlQuery = session.createSQLQuery(queryString);
sqlQuery.addScalar("XYZ_ID", StandardBasicTypes.LONG).addScalar(...);// several calls of addScalar.
sqlQuery.setResultTransformer(new MyPOJOResultTransformer()); //Transforms the results to a list of "MyPOJOResult", that's not an entity!
//...
List<MyPOJOResult> results = sqlQuery.list();
No I try to migrate to Hibernate 5.2. So I changed SQLQuery to NativeQuery. Now, the methods "addScalar" and "setResultTransformer" are deprecated, "setResultTransformer" without explanation.
My questions:
- What's the alternative? Do I have to define a "@SqlResultSetMapping" and call
Code:
NativeQuery<???MyPOJOResult???> sqlQuery = session.createNativeQuery(queryString, "myResultSetMapping");
(To be honest, I am a little bit hesitantly, because I think it's difficult to make this change, resulting in a very complex annotation...?!)
- Is there a possibility that sqlQuery.getResultList() returns an instance of "MyPOJOResult", that's not an entity? (My ResultTransformer returned a simple POJO, but not an entity!)
Or ist there an alternative approach?
Thank you!