Reputation: 2107
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?
Upvotes: 42
Views: 48966
Reputation:
Hibernate 6 has not been released yet. However, based on this issue ResultTransformer interface was split into the 2 functional interfaces: TupleTransformer and ResultListTransformer.
Upvotes: 4
Reputation: 65
Since Hibernate 5.2 uses Java 8 you can use stream api
List<EmployeeDto> resultList = session
.createQuery(" from Employee", Employee.class)
.stream()
.map((employee) -> {
return new EmployeeDto(employee);
})
.collect(Collectors.toList());
This code will also give some performance improvement.
Upvotes: -12
Reputation: 2279
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.
Upvotes: 14
Reputation: 4093
Don't use session.createQuery(hql,transformerClass);
if you select multiple items in your query, use the old deprecated method instead.
Upvotes: -1