Cannot create TypedQuery for query with more than one return
14,859
Solution 1
I go the same error: Cannot create TypedQuery for query with more than one return using requested result type
Solution:
Having a Query like this:
Select e.fieldA, e.fieldB, e.fieldC From Entity e
You have to declare a constructor with the parameters specified on query:
package somepackage;
public class Entity {
...
public class Entity() {}
public class Entity(Type fieldA, Type fieldB, Type fieldC) {
this.fieldA = fieldA;
this.fieldB = fieldB;
this.fieldC = fieldC;
}
....
}
Finally, modify your query
Select NEW somepackage.Entity(e.fieldA, e.fieldB, e.fieldC) From Entity e
You are indicating how the objectes will be created.
Solution 2
This seems to be this bug: https://hibernate.onjira.com/browse/HHH-6304
It is apparently fixed in version 4.1.5.
Related videos on Youtube
Author by
saru
Updated on June 04, 2022Comments
-
saru almost 2 years
I am using the following JPA query and i am getting the java.lang.IllegalArgumentException: Cannot create TypedQuery for query with more than one return Exception.
TypedQuery<RaBdrRating> uQuery = (TypedQuery<RaBdrRating>)entityManager.createQuery(" SELECT r.activePackage,SUM(r.duration),SUM(r.charge),COUNT(r) FROM RaBdrRating r WHERE r.callType = :callType and r.startDate between :startDate and :endDate GROUP BY r.activePackage",RaBdrRating.class); uQuery.setParameter("callType", model.getCallType()); uQuery.setParameter("startDate",startDate); uQuery.setParameter("endDate",endDate); List<RaBdrRating> listOfPackages = uQuery.getResultList();
Can any one tell me what is wrong in my query.....I am new to JPA and i am not getting what is the problem and strucked up here.If any one have idea please tell me.
-
Nayan Wadekar about 12 yearsSimilar one, can refer stackoverflow.com/a/10010154/366964 & stackoverflow.com/a/4536802/366964
-