javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount

Hibernate JIRA | Michael Plöd | 10 years ago
  1. 0

    [HHH-2626] Bug in handling null references to Components / Embeddables when using session / entityManager.merge() - Hibernate JIRA

    atlassian.net | 1 year ago
    javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount
  2. 0

    I found a bug, that got introduced by adding functionality to the class TypeFactory in Hibernate 3.2.3. The Method TypeFactory#replaceAssociations(...) now has some special handling regarding components / embeddables. But if such a component is null, wich is fair enough, Hibernate will provoke a NullPointerException in sun.reflect.UnsafeFieldAccessorImpl.ensureObj(...): Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236) at de.ploed.test.EntityManagerTest.main(EntityManagerTest.java:22) Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35) at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64) at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70) at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83) at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353) at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348) at org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:556) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227) ... 1 more Caused by: java.lang.NullPointerException at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36) at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18) at java.lang.reflect.Field.get(Field.java:357) at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32) ... 15 more I think that the handling of target[i] in Line 556 of org.hibernate.type.TypeFactory is not null safe. I have created a patch for this and the bug above appears to be fixed in this patch. In my humble opinion this bug makes it impossible to merge any entity / value object containing a null reference to another value object. However this bug is not present when using session.save or session.saveOrUpdate. I was able to reproduce the bug in Hibernate Core 3.2.4.sp1, 3.2.4 and 3.2.3 .. It is not present in Hibernate Core Versions <= 3.2.2 Attached to this task are the following files: patch.txt - my patch proposal TestCase.zip - Test Case Please get back to me if you have any further questions! Cheers, Mike

    Hibernate JIRA | 10 years ago | Michael Plöd
    javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount
  3. 0

    I found a bug, that got introduced by adding functionality to the class TypeFactory in Hibernate 3.2.3. The Method TypeFactory#replaceAssociations(...) now has some special handling regarding components / embeddables. But if such a component is null, wich is fair enough, Hibernate will provoke a NullPointerException in sun.reflect.UnsafeFieldAccessorImpl.ensureObj(...): Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:647) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:236) at de.ploed.test.EntityManagerTest.main(EntityManagerTest.java:22) Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35) at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64) at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70) at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83) at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353) at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348) at org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:556) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53) at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665) at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227) ... 1 more Caused by: java.lang.NullPointerException at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36) at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18) at java.lang.reflect.Field.get(Field.java:357) at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32) ... 15 more I think that the handling of target[i] in Line 556 of org.hibernate.type.TypeFactory is not null safe. I have created a patch for this and the bug above appears to be fixed in this patch. In my humble opinion this bug makes it impossible to merge any entity / value object containing a null reference to another value object. However this bug is not present when using session.save or session.saveOrUpdate. I was able to reproduce the bug in Hibernate Core 3.2.4.sp1, 3.2.4 and 3.2.3 .. It is not present in Hibernate Core Versions <= 3.2.2 Attached to this task are the following files: patch.txt - my patch proposal TestCase.zip - Test Case Please get back to me if you have any further questions! Cheers, Mike

    Hibernate JIRA | 10 years ago | Michael Plöd
    javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of de.ploed.test.MonetaryAmount.amount
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    can't unmarshal wrapped elements

    Oracle Community | 9 years ago | 843834
    java.lang.NullPointerException

  1. adawolfs 4 times, last 4 months ago
  2. jk 11 times, last 5 months ago
  3. MyInnos 7 times, last 7 months ago
3 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.NullPointerException

    No message provided

    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj()
  2. Java RT
    Field.get
    1. sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
    2. sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:18)
    3. java.lang.reflect.Field.get(Field.java:357)
    3 frames
  3. Hibernate
    TypeFactory.replaceAssociations
    1. org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:32)
    2. org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
    3. org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
    4. org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83)
    5. org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
    6. org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348)
    7. org.hibernate.type.TypeFactory.replaceAssociations(TypeFactory.java:556)
    7 frames
  4. Hibernate
    SessionImpl.merge
    1. org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:366)
    2. org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:195)
    3. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
    4. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
    5. org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
    6. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
    7. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
    7 frames
  5. Hibernate EJB
    AbstractEntityManagerImpl.merge
    1. org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
    1 frame
  6. de.ploed.test
    EntityManagerTest.main
    1. de.ploed.test.EntityManagerTest.main(EntityManagerTest.java:22)
    1 frame