首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >升级到SpringDataJPA1.10.3后带有“选择新”的NoSuchMethodException

升级到SpringDataJPA1.10.3后带有“选择新”的NoSuchMethodException
EN

Stack Overflow用户
提问于 2016-09-27 16:10:27
回答 1查看 561关注 0票数 0

在将Spring数据JPA从1.9.2升级到1.10.3之后,我遇到了一个问题。

我有以下存储库:

代码语言:javascript
复制
public interface ShipmentStatisticRepository extends JpaRepository<Shipment, Long> {

    ...

    @Query("select new de.l.b.model.dto.shipment.ShipmentStatistic(s.createdYmd, count(distinct s.oid), count(op), sum(op.price)) " +
            "from Shipment s " +
            "join s.orderPosition op " +
            "where s.created between ?1 and ?2 " +
            "group by s.createdYmd")
    List<ShipmentStatistic> findPerDayBetweenCreated(Date from, Date to);

    ...
}

当我调用此方法时,会得到以下异常:

代码语言:javascript
复制
 org.springframework.dao.InvalidDataAccessApiUsageException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList; nested exception is java.lang.IllegalArgumentException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList
    at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384)
    at org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:122)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:436)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    at com.sun.proxy.$Proxy154.findPerDayBetweenCreated(Unknown Source)
    at de.l.b.hazelcast.map.ShipmentStatisticPerDayMapLoader.getShipmentStatistic(ShipmentStatisticPerDayMapLoader.java:40)
    at de.l.b.hazelcast.map.AbstractShipmentStatisticMapLoader.load(AbstractShipmentStatisticMapLoader.java:38)
    at de.l.b.hazelcast.map.AbstractShipmentStatisticMapLoader.loadAll(AbstractShipmentStatisticMapLoader.java:48)
    at com.hazelcast.map.impl.MapStoreWrapper.loadAll(MapStoreWrapper.java:143)
    at com.hazelcast.map.impl.mapstore.AbstractMapDataStore.loadAll(AbstractMapDataStore.java:56)
    at com.hazelcast.map.impl.mapstore.writebehind.WriteBehindStore.loadAll(WriteBehindStore.java:205)
    at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.loadAndGet(BasicRecordStoreLoader.java:170)
    at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.doBatchLoad(BasicRecordStoreLoader.java:143)
    at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.loadValuesInternal(BasicRecordStoreLoader.java:129)
    at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader.access$100(BasicRecordStoreLoader.java:54)
    at com.hazelcast.map.impl.recordstore.BasicRecordStoreLoader$GivenKeysLoaderTask.call(BasicRecordStoreLoader.java:112)
    at com.hazelcast.util.executor.CompletableFutureTask.run(CompletableFutureTask.java:67)
    at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:212)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
    at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
Caused by: java.lang.IllegalArgumentException: Could not instantiate Collection type: org.apache.openjpa.kernel.DelegatingResultList
    at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:208)
    at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:151)
    at org.springframework.data.repository.query.ResultProcessor.processResult(ResultProcessor.java:146)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:119)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:104)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    ... 25 more
Caused by: java.lang.InstantiationException: org.apache.openjpa.kernel.DelegatingResultList
    at java.lang.Class.newInstance(Class.java:427)
    at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:204)
    ... 39 more
Caused by: java.lang.NoSuchMethodException: org.apache.openjpa.kernel.DelegatingResultList.<init>()
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.newInstance(Class.java:412)
    ... 40 more

看起来存储库无法解析正确的构造函数来填充我的投影。在1.9.2版本中,一切都很好。

这是我的投影课:

代码语言:javascript
复制
public class ShipmentStatistic implements Serializable {

    private Date date;
    private long totalParcelsSent;
    private long totalPositionsSent;
    private long totalValue;

    public ShipmentStatistic(Date date) {
        this.date = date;
        this.totalPositionsSent = 0;
        this.totalParcelsSent = 0;
        this.totalValue = 0;
    }

    public ShipmentStatistic(Date date, long totalParcelsSent, long totalPositionsSent, long totalValue) {
        this.date = date;
        this.totalPositionsSent = totalPositionsSent;
        this.totalParcelsSent = totalParcelsSent;
        this.totalValue = totalValue;
    }

    public ShipmentStatistic add(ShipmentStatistic other) {
        this.totalPositionsSent += other.totalPositionsSent;
        this.totalParcelsSent += other.totalParcelsSent;
        this.totalValue += other.totalValue;

        return this;
    }

    // getter and setter
}  

我做了一个随机射击,并试图添加一个默认的构造函数,但没有成功。

我看不到我的错误,尤其是唯一的更改是框架更新。顺便说一下,我们使用OpenJPA 2.2.2作为持久性API。我升级到了当前的2.4.1版本,但这也没有效果。

有什么建议吗?这可能是Spring与OpenJPA的结合中的一个缺陷吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-03 04:30:03

从堆栈跟踪来看,openjpa似乎在搜索默认的构造函数。您能否尝试在ShipmentStatistic.java中显式地添加默认构造函数?

JPA规范要求使用默认的无参数构造函数。arg

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39729529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档