I wanna use query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
to get a List<Map>
. But I got a exception:
java.lang.NoSuchMethodError: org.hibernate.query.Query.setResultTransformer(Lorg/hibernate/transform/ResultTransformer;)Lorg/hibernate/Query;
I can't find the implemented class of org.hibernate.query.Query
. The method setResultTransformer
is in org.hibernate.Query
.
And why is the org.hibernate.Query deprecated?
Hibernate's ResultTransformers provide various ways to map the result of your query to different data structures. They were commonly used in Hibernate 4, got deprecated in Hibernate 5 and got replaced by the functional interfaces TupleTransformer and ResultListTransformer in Hibernate 6.
The ResultTransformer comes with a legacy definition which is not following the Functional Interface syntax. Hence, we cannot use a lambda in this example. Hibernate 6.0 aims to overcome this issue, so that's why the Hibernate ORM 5.2 ResultTransformer is deprecated.
Which method replaced setResultTransformer ? For the moment, there is no replacement. In 6.0, the ResultTransformer will be replaced by a @FunctionalInterface , but the underlying mechanism of transforming the Object[] property values will probably be the same.
public interface ResultTransformer extends Serializable. Implementors define a strategy for transforming query results into the actual application-visible query result list.
The ResultTransformer comes with a legacy definition which is not following the Functional Interface syntax. Hence, we cannot use a lambda in this example. Hibernate 6.0 aims to overcome this issue, so that’s why the Hibernate ORM 5.2 ResultTransformer is deprecated. Nevertheless, an alternative will be provided, so the concept we are discussing in this article is going to stand still even in Hibernate 6.
https://vladmihalcea.com/why-you-should-use-the-hibernate-resulttransformer-to-customize-result-set-mappings/
Hibernate 6 has not been released yet. However, based on this issue ResultTransformer interface was split into the 2 functional interfaces: TupleTransformer and ResultListTransformer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With