spring-data-2.0.6 java.lang.IllegalArgumentException: не удалось найти PersistentEntity для класса типов HibernateProxy - PullRequest
0 голосов
/ 03 мая 2018

Сбой данных Spring при попытке доступа к связанному экземпляру HibernateProxy (привязка с отложенной выборкой).

Ошибка с этими последними версиями:

  • весна-данных 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()

Ленивый выбор связанной сущности. В результате создается экземпляр 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)

1 Ответ

0 голосов
/ 03 мая 2018

Известная несовместимость между данными о Spring и Hibernate 5.3 https://jira.spring.io/projects/SPR/issues/SPR-16569

Решение 1) понизить версию hibernate до версии 5.2 или более ранней.

Решение 2) установить hibernate на использование javassist вместо ByteBuddy

hibernate.bytecode.provider = Javassist

Спасибо, Йенс Шаудер

...