spring-data-2.0.6 java.lang.IllegalArgumentException:找不到类型为HibernateProxy的PersistentEntity

问题描述 投票:0回答:1

尝试访问关联的HibernateProxy实例(延迟提取的关联)时,Spring数据失败。

这些最新版本出错:

  • 弹簧数据2.0.6.RELEASE
  • org.hibernate作为:休眠核心:5.3.0.CR2

实体属性:

@Entity @Table(name =“WORKSPACE”,uniqueConstraints = @UniqueConstraint(columnNames = {“EXT_KEY”,“SERVICE_ID”}))公共类Workspace {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SERVICE_ID", nullable = false, insertable = false, updatable = false)
public Service getService()

Lazy在HibernateProxy实例中获取了关联的实体结果,该实例因以下错误而失败:

java.lang.IllegalArgumentException: Couldn't find PersistentEntity for type class xxx.xxx.xxx.xxx.xxx.Service$HibernateProxy$zKdvHMKB!
    at org.springframework.data.mapping.context.PersistentEntities.lambda$getRequiredPersistentEntity$2(PersistentEntities.java:78) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_111]
    at org.springframework.data.mapping.context.PersistentEntities.getRequiredPersistentEntity(PersistentEntities.java:77) ~[spring-data-commons-2.0.6.RELEASE.jar:2.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:72) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:55) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.lambda$null$0(RepositoryPropertyReferenceController.java:136) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_111]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController$ReferencedProperty.mapValue(RepositoryPropertyReferenceController.java:450) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.lambda$followPropertyReference$2(RepositoryPropertyReferenceController.java:118) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.lambda$doWithReferencedProperty$16(RepositoryPropertyReferenceController.java:423) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_111]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.doWithReferencedProperty(RepositoryPropertyReferenceController.java:420) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(RepositoryPropertyReferenceController.java:144) ~[spring-data-rest-webmvc-3.0.6.RELEASE.jar:3.0.6.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]

适用于早期版本

  • 弹簧数据1.5.12.RELEASE
  • org.hibernate作为:休眠核心:5.0.4.Final

临时解决方法 - 将关联的实体提取类型设置为EAGER

@ManyToOne(fetch = FetchType.EAGER)
java hibernate spring-boot spring-data spring-data-jpa
1个回答
0
投票

spring-data和hibernate 5.3 https://jira.spring.io/projects/SPR/issues/SPR-16569之间已知的不兼容性

解决方案1)将hibernate版本降级到5.2或更早版本。

解决方案2)将hibernate设置为使用javassist而不是ByteBuddy

hibernate.bytecode.provider =了Javassist

谢谢Jens Schauder

© www.soinside.com 2019 - 2024. All rights reserved.