Spring data is failing when attempting to access an associated HibernateProxy instance (lazy fetched association).
Error with these latest versions:
- spring-data-2.0.6.RELEASE
- org.hibernate:hibernate-core:5.3.0.CR2
Entity Attribute with:
@Entity @Table(name = "WORKSPACE", uniqueConstraints = @UniqueConstraint(columnNames = { "EXT_KEY", "SERVICE_ID" })) public class Workspace {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SERVICE_ID", nullable = false, insertable = false, updatable = false)
public Service getService()
Lazy fetched associated entity Results in a HibernateProxy instance which fails with the following error:
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]
Works with earlier versions
- spring-data-1.5.12.RELEASE
- org.hibernate:hibernate-core:5.0.4.Final
Temporary workaround - set the associated entity fetch type to EAGER
@ManyToOne(fetch = FetchType.EAGER)
Couldn't find PersistentEntity for type class xxx.xxx.xxx.xxx.xxx.Service
? It says cant find persistent entity. Can you post some snippet? – Karthik R