Affects Hibernate ORM 6.2, probably also 6.1 and 6.0, but definitely not 5.6.
This model:
@Entity(name = "entitya")
public static class EntityA {
@Id
private Integer id;
@Embedded
private EmbeddedValue embedded = new EmbeddedValue();
public EntityA() {
}
private EntityA(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public EmbeddedValue getEmbedded() {
return embedded;
}
public void setEmbedded(EmbeddedValue embedded) {
this.embedded = embedded;
}
}
@Embeddable
public static class EmbeddedValue implements Serializable {
@OneToOne(mappedBy = "entityA", fetch = FetchType.LAZY)
private EntityB entityB;
public EmbeddedValue() {
}
public EntityB getEntityB() {
return entityB;
}
public void setEntityB(
EntityB entityB) {
this.entityB = entityB;
}
}
@Entity(name = "entityb")
public static class EntityB {
@Id
private Integer id;
@OneToOne
private EntityA entityA;
public EntityB() {
}
private EntityB(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public EntityA getEntityA() {
return entityA;
}
public void setEntityA(EntityA entityA) {
this.entityA = entityA;
}
}
Leads to this stacktrace upon loading EntityA:
org.hibernate.InstantiationException: Could not instantiate entity: : org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest$EmbeddedValue
at org.hibernate.metamodel.internal.EmbeddableInstantiatorPojoStandard.instantiate(EmbeddableInstantiatorPojoStandard.java:84)
at org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.createCompositeInstance(AbstractEmbeddableInitializer.java:326)
at org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.prepareCompositeInstance(AbstractEmbeddableInitializer.java:242)
at org.hibernate.sql.results.graph.embeddable.AbstractEmbeddableInitializer.initializeInstance(AbstractEmbeddableInitializer.java:190)
at org.hibernate.sql.results.internal.StandardRowReader.coordinateInitializers(StandardRowReader.java:153)
at org.hibernate.sql.results.internal.StandardRowReader.readRow(StandardRowReader.java:98)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:184)
at org.hibernate.sql.results.spi.ListResultsConsumer.consume(ListResultsConsumer.java:33)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:443)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:166)
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:91)
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31)
at org.hibernate.loader.ast.internal.SingleIdLoadPlan.load(SingleIdLoadPlan.java:140)
at org.hibernate.loader.ast.internal.SingleIdLoadPlan.load(SingleIdLoadPlan.java:110)
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderStandardImpl.load(SingleIdEntityLoaderStandardImpl.java:72)
at org.hibernate.persister.entity.AbstractEntityPersister.doLoad(AbstractEntityPersister.java:4338)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4328)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:589)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromCacheOrDatasource(DefaultLoadEventListener.java:575)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:544)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:537)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:199)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:238)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:103)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:75)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:118)
at org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1241)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1229)
at org.hibernate.loader.access.IdentifierLoadAccessImpl.doLoad(IdentifierLoadAccessImpl.java:192)
at org.hibernate.loader.access.IdentifierLoadAccessImpl.lambda$load$1(IdentifierLoadAccessImpl.java:158)
at org.hibernate.loader.access.IdentifierLoadAccessImpl.perform(IdentifierLoadAccessImpl.java:105)
at org.hibernate.loader.access.IdentifierLoadAccessImpl.load(IdentifierLoadAccessImpl.java:158)
at org.hibernate.internal.SessionImpl.get(SessionImpl.java:1021)
at org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest.lambda$test$1(LazyOneToOneMappedByInEmbeddedTest.java:51)
at org.hibernate.testing.transaction.TransactionUtil2.inTransaction(TransactionUtil2.java:96)
at org.hibernate.testing.transaction.TransactionUtil2.lambda$inTransaction$0(TransactionUtil2.java:76)
at org.hibernate.testing.transaction.TransactionUtil2.inSession(TransactionUtil2.java:35)
at org.hibernate.testing.transaction.TransactionUtil2.inTransaction(TransactionUtil2.java:74)
at org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase.inTransaction(BaseNonConfigCoreFunctionalTestCase.java:591)
at org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest.test(LazyOneToOneMappedByInEmbeddedTest.java:50)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.hibernate.PropertyAccessException: Could not set value of type [org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1] : `org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest$EmbeddedValue.entityB` (setter)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:79)
at org.hibernate.property.access.spi.EnhancedSetterImpl.set(EnhancedSetterImpl.java:38)
at org.hibernate.metamodel.mapping.internal.AbstractEmbeddableMapping.lambda$setValues$1(AbstractEmbeddableMapping.java:106)
at org.hibernate.metamodel.mapping.internal.EmbeddableMappingTypeImpl.forEachAttributeMapping(EmbeddableMappingTypeImpl.java:720)
at org.hibernate.metamodel.mapping.internal.AbstractEmbeddableMapping.setValues(AbstractEmbeddableMapping.java:105)
at org.hibernate.metamodel.internal.EmbeddableInstantiatorPojoStandard.instantiate(EmbeddableInstantiatorPojoStandard.java:78)
... 54 more
Caused by: java.lang.IllegalArgumentException: Can not set org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest$EntityB field org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.LazyOneToOneMappedByInEmbeddedTest$EmbeddedValue.entityB to org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer$1
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.base/java.lang.reflect.Field.set(Field.java:780)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:52)
... 59 more