开发者

SELECT NEW in JPQL

I'm having an issue with a SELECT NEW query.

Query q = em.createQuery(
           "SELECT NEW com.bcbst.odstats.ejb.RangeStats(a.folderName, SUM(a.hits)) " +  
           "FROM ODStat a GROUP BY a.folderName");
return q.getResultList();

I get the following stacktrace when I try to run this query. RangeStats does have public methods, the FQN is accurate, in fact RangeStats resides in the same package as the class making the query. I've done queries on ODStat before, so I'm also confident that a.folderName and a.hits is OK.

I'm developing with RAD 7.5, WAS 7, OpenJPA 1.2.1, MS SQL JDBC Driver 1.2.

    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:896)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)
Caused by: javax.ejb.E开发者_如何转开发JBException: See nested exception; nested exception is: 
<openjpa-1.2.1-SNAPSHOT-r422266:686069 nonfatal user error> 
org.apache.openjpa.persistence.ArgumentException: Result type "class 
com.bcbst.odstats.ejb.RangeStats" does not have any public fields or setter methods 
for the projection or aggregate result element "jpqlalias1", nor does it have a 
generic put(Object,Object) method that can be used, nor does it have a public 
constructor that takes the types [class java.lang.String, long].

Caused by: <openjpa-1.2.1-SNAPSHOT-r422266:686069 nonfatal user error> 
org.apache.openjpa.persistence.ArgumentException: Result type "class 
com.bcbst.odstats.ejb.RangeStats" does not have any public fields or setter methods 
for the projection or aggregate result element "jpqlalias1", nor does it have a 
generic put(Object,Object) method that can be used, nor does it have a public 
constructor that takes the types [class java.lang.String, long].

at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:139)
at org.apache.openjpa.kernel.ResultPacker.<init>(ResultPacker.java:102)
at org.apache.openjpa.kernel.QueryImpl.getResultPacker(QueryImpl.java:1262)
at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1212)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:805)


Found the problem. The constructor accepted (String, int) when it needed (String, long).


Follow me

 public Company(String name, int iva, String businessArea, String coreBusiness) {
    this.name = name;
    this.iva = iva;
    this.businessArea = businessArea;
    this.coreBusiness = coreBusiness;
    }

Query query = session.createQuery("select new Company (name, iva, businessArea, coreBusiness)  from Company");


obs : org hibernate
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜