I have two entity classes which are byte-code instrumented: Person and Address. A person has an optional one-to-one address. The PK of the Address class is the FK of Person.
Code:
@Entity
public class Person {
...
@OneToOne(mappedBy = "person", cascade = ALL, orphanRemoval = true)
@LazyToOne(LazyToOneOption.NO_PROXY)
@PrimaryKeyJoinColumn
private Address address;
...
}
@Entity
public class Address {
...
@Id
private Long id;
@MapsId
@OneToOne
private Person person;
...
}
When I attempt to delete a Person record, I get the following error:
Quote:
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of Person.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:341) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4323) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:65) ~[hibernate-entitymanager-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:107) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:954) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:939) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:262) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.event.internal.DefaultDeleteEventListener.cascadeBeforeDelete(DefaultDeleteEventListener.java:324) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.event.internal.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:263) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:161) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:946) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:925) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
...
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field Person.id to org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer$1
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) ~[na:1.7.0_02]
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) ~[na:1.7.0_02]
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55) ~[na:1.7.0_02]
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36) ~[na:1.7.0_02]
at java.lang.reflect.Field.get(Field.java:372) ~[na:1.7.0_02]
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59) ~[hibernate-core-4.1.5.SP1.jar:4.1.5.SP1]
If I remove the byte-code instrumentation, the cascaded delete works as expected.
Any ideas about what I might be doing wrong?
Thanks
Andrew