代码之家  ›  专栏  ›  技术社区  ›  dharga

在JPQL中选择“新建”

  •  4
  • dharga  · 技术社区  · 15 年前

    我对选择新查询有问题。

    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();
    

    我得到以下信息 stacktrace 当我尝试运行此查询时。 RangeStats 确实有公共方法,fqn是准确的,事实上rangestats与进行查询的类位于同一个包中。我以前在odstat上做过查询,所以我也相信a.foldername和a.hits是可以的。

    我正在开发RAD7.5、WAS7、OpenJPA1.2.1、MS SQL JDBC驱动程序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.EJBException: 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)
    
    2 回复  |  直到 8 年前
        1
  •  5
  •   mskfisher KeithS    13 年前

    发现了问题。 施工单位接受 (String, int) 当需要时 (String, long) .

        2
  •  0
  •   Tiago Medici    8 年前

    跟着我

     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