-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Alternative to the use of ResultTransformer?
PostPosted: Tue Sep 13, 2016 6:30 am 
Newbie

Joined: Tue Sep 13, 2016 5:10 am
Posts: 1
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!


Top
 Profile  
 
 Post subject: Re: Alternative to the use of ResultTransformer?
PostPosted: Tue Sep 13, 2016 9:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hibernate 6.0 is going to come with a different ResultTransformer that can be exposed as a @FunctionalInterface.

IN your case, you're using the ResultTransformer because there is no other support for DTO projections when using native queries. With entity queries we have the "select new" clause, but that's just for JPQL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.