2

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.

4

2 回答 2

3

我遇到同样的错误:Cannot create TypedQuery for query with more than one return using requested result type

解决方案:

有这样的查询:

Select e.fieldA, e.fieldB, e.fieldC From Entity e

您必须使用查询中指定的参数声明构造函数:

    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;
       }
    ....
    }

最后,修改您的查询

Select NEW somepackage.Entity(e.fieldA, e.fieldB, e.fieldC) From Entity e

您正在指示如何创建对象。

于 2013-02-20T22:40:16.587 回答
2

这似乎是这个错误:https ://hibernate.onjira.com/browse/HHH-6304

它显然已在 4.1.5 版中修复。

于 2012-07-17T14:53:00.897 回答