[英]Why does my intermediate repository interface cause trouble after upgrading from Spring Data JPA 1.4.x to a more recent version (e.g. 1.7.1)?
No [ManagedType] was found for the key class [java.lang.Object] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>java.lang.Object</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.entityEmbeddableManagedTypeNotFound(MetamodelImpl.java:173) ~[org.eclipse.persistence.jpa-2.5.2.jar:na]
at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.managedType(MetamodelImpl.java:495) ~[org.eclipse.persistence.jpa-2.5.2.jar:na]
It's strange because reverting to Spring Data JPA 1.4.3.RELEASE fixed the problem. 这很奇怪,因为恢复为Spring Data JPA 1.4.3.RELEASE可以解决此问题。 But we would like to understand what is causing this. 但是我们想了解是什么原因造成的。 The interface repository we're using looks like this 我们正在使用的接口存储库如下所示
@Repository
public interface BaseRepository<T, K extends Serializable>
extends JpaRepository<T, K>,
QueryDslPredicateExecutor<T> {
}
and 和
@Repository
public interface PersonRepository extends BaseRepository<Person, Long> { }
In the meantime, we'll use the old version, but I'm not sure where to look in order to fix this. 在此期间,我们将使用旧版本,但是我不确定要解决此问题的位置。 Any ideas? 有任何想法吗?
As stated in the reference documentation , intermediate repository interfaces need to be annotated with @NoRepositoryBean
. 如参考文档中所述,中间存储库接口需要使用@NoRepositoryBean
进行注释。 Generally speaking, Spring Data repositories do not need to be annotated with @Repository
. 一般来说,Spring Data存储库不需要使用@Repository
进行注释。
Spring Data JPA versions until 1.4.x used a lazy instantiation model for repository interfaces. 直到1.4.x为止的Spring Data JPA版本都将延迟实例化模型用于存储库接口。 This means that if no one explicitly referred to a particular repository interface, no repository bean was created and thus the generic typing not evaluated. 这意味着,如果没有人明确引用特定的存储库接口,则不会创建任何存储库bean,因此不会评估泛型类型。
In Spring Data 1.5 M1 we changed that (more precisely, Spring Data Commons 1.7 M1 - see this ticket , but that is what JPA 1.5 M1 depended on) to align with the default bean instantiation model that's used throughout the Spring container (eager instantiation is the default). 在Spring Data 1.5 M1中,我们进行了更改(更确切地说,是Spring Data Commons 1.7 M1-请参见此票证 ,但这是JPA 1.5 M1所依赖的),以与在整个Spring容器中使用的默认bean实例化模型保持一致(渴望的实例化是默认值)。
This means, that previously erroneous intermediate interfaces like your BaseRepository
now start to fail the context bootstrapped as their generics information is evaluated at startup. 这意味着,以前错误的中间接口(如BaseRepository
现在开始在引导时无法进行上下文引导,因为在启动时会评估其泛型信息。 As indicated above, the suggested workaround is using @NoRepositoryBean
on the intermediate interface as this will cause the interface to be ignored by Spring Data and there will be no attempt to create a Spring bean for it at all. 如上所述,建议的解决方法是在中间接口上使用@NoRepositoryBean
,因为这将导致该接口被Spring Data忽略,并且完全不会尝试为其创建Spring Bean。
Do you use BaseRepository somewhere as a bean? 您是否在某处将BaseRepository用作Bean? If not, maybe remove the @Repository annotation from it, or replace with @NoRepositoryBean 如果不是,则可以从中删除@Repository批注,或替换为@NoRepositoryBean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.