spring引导从2.2.1.release升级到2.3.1.release(测试失败)

aor9mmx1  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(185)

当从spring2.1.2.release升级到2.3.1.release面临问题时,完整配置的要点是。补充

<spring-boot.version>
       2.3.1.RELEASE
</spring-boot.version>

<dependency>
    <groupId>
        org.springframework.boot
    </groupId>
    <artifactId>
        spring-boot-starter-validation
    </artifactId>
</dependency>

保持其余版本和配置相同。cucumber版本-3.0.2 junit版本-4.12
所以在改变之后,如果我们尝试运行测试,它们就会失败。我们正在呼叫存储库的 deleteAll() 当我们在日志中看到这些异常时,如果我们对 saveAndFlush() 方法我们看不到例外。虽然这个问题不是由于 cucumber ,但似乎在缩小范围之后
感谢您的帮助,如果我的具体情况需要更多的信息,我可以添加建议的细节。
代码示例为:foorrepository.java:

package com.foo.respositories;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.foo.entities.FooEntity;
@Transactional
@Repository
public interface FooRepository extends JpaRepository<FooEntity, LocalDate> {
    @Modifying
    default void create(FooEntity entity) {
        this.saveAndFlush(entity);
    }
}

fooentity.java文件:

package com.foo.entities;
import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.Data;
import org.hibernate.envers.Audited;
@Entity
@Audited
@Data
public class FooEntity {
    @Id
    private LocalDate date;
    private BigDecimal rate;
}

日志的跟踪如下。

org.springframework.dao.InvalidDataAccessApiUsageException: id to load is required for loading; nested exception is java.lang.IllegalArgumentException: id to load is required for loading
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:374)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible (AbstractEntityManagerFactoryBean.java :528)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy282.deleteAll(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 ( NativeMethodAccessImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)
at com.sun.proxy.$Proxy158.deleteAll(Unknown Source)
at *.we clear out database
Caused by: java.lang.IllegalArgumentException: id to load is required for loading
at org.hibernate.event.spi.LoadEvent.<init> (LoadEvent.java:96)
at org.hibernate.event.spi.LoadEvent.<init> (LoadEvent.java:64)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.doLoad(SessionImpl.java:2781)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.lambda$load$1 (SessionImpl.java:2765)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.perform(SessionImpl.java:2721)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2765)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题