Spring Boot Hibernate在Sping Boot 3 Hibernate 6迁移后,按超类JpaRepository查询时无法解析子类的属性

a1o7rhls  于 2023-01-13  发布在  Spring
关注(0)|答案(1)|浏览(165)

我正在尝试从Spring Boot 2.7迁移到Spring Boot 3.0。
我的实体使用Joined继承类型和抽象超类类型的JpaRepository,它们处于一个等级关系中。自从迁移以来,当我尝试在JpaRepository上运行方法findByKey()时,我的集成测试失败,如下面的例子所示:

Caused by: org.hibernate.HibernateException: Unable to resolve property: requestItemConfiguration
    at org.hibernate.tuple.entity.EntityMetamodel.getPropertyIndex(EntityMetamodel.java:872)
    at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyIndex(AbstractEntityPersister.java:2781)
    at org.hibernate.sql.results.graph.entity.internal.BatchEntitySelectFetchInitializer.endLoading(BatchEntitySelectFetchInitializer.java:226)
    at org.hibernate.sql.results.internal.StandardRowReader.finishUp(StandardRowReader.java:161)
    at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:168)
    at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:32)
    at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443)
    at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166)
    at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91)
    at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
    at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:102)
    at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:305)
    at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:246)
    at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:546)
    at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
    at org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1032)
    at org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:457)
    at org.hibernate.query.sqm.internal.QuerySqmImpl.getSingleResult(QuerySqmImpl.java:1062)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:193)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:90)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:148)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:136)
    at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:136)
    at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:120)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:77)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
    ... 87 common frames omitted

在调试代码时,我发现Hibernate试图将子类的属性设置为抽象超类EntityMetamodel,但失败了。为了在Hibernate 6中工作,应该做哪些更改?
实体层次结构:
x一个一个一个一个x一个一个二个一个x一个一个三个一个
Jpa存储库

public interface JpaRequestRepository extends JpaRepository<JpaRequest, Long> {

    JpaRequest findByKey(String key);
.
.
.
aiazj4mn

aiazj4mn1#

升级到Sping Boot 3.0.1 / Hibernate 6.1.6似乎已经解决了这个问题。

相关问题