简体   繁体   English

从Spring Data JPA 1.4.x升级到更新的版本(例如1.7.1)后,为什么我的中间存储库接口会引起麻烦?

[英]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? 有任何想法吗?

tl;dr TL;博士

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进行注释。

Details 细节

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.

相关问题 Spring boot 1.4.x 和自定义 CharsetProvider - Spring boot 1.4.x and custom CharsetProvider 为什么使用 JUnit 5 运行此 Spring Data JPA Repository 测试会导致 ParameterResolutionException? - Why does running this Spring Data JPA Repository test with JUnit 5 cause a ParameterResolutionException? 使用该类是否更有效,例如Hashtable而不是接口,例如Map? - Is it more efficient to use the class, e.g. Hashtable than the interface, e.g. Map? 在 spring-boot 1.4.x 中添加原因短语 - Add reason phrase back in spring-boot 1.4.x 如何使用@Query 向标准 CRUD Spring JPA 存储库方法添加其他方法(例如按名称、角色、类别搜索)? - How To Add Additional Methods To Standard CRUD Spring JPA Repository Methods Using @Query (e.g. Search By Name, Role, Category)? 升级 Spring 数据 jpa 和 commons 导致存储库接口上的“无法解析匹配的构造函数” - Upgrading Spring data jpa and commons causes 'Could not resolve matching constructor' on repository interface 为什么JPA规范(包括2.0)或Hibernate扩展不允许您为@Version注释指定生成器(例如Oracle序列) - Why doesn't the JPA spec (including 2.0) or Hibernate extension allow u to specify a generator e.g. Oracle sequence for the @Version annotation 如何从Java清除Memcached(1.4.x)统计信息 - How to clear Memcached (1.4.x) stats from java 为具有主键的实体定义弹簧数据JPA存储库接口,该主键也是JPA 2.x中的外键 - Defining a spring-data JPA repository interface for entity with primary key that is also a foreign key in JPA 2.x 无法创建Spring Data JPA存储库 - Trouble creating Spring Data JPA repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM