org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of dummy.Child.setChildren

Hibernate JIRA | Nguyen Hau Giang | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    When merging an entity parent that has property children mapped as sorted map(sorted=natural), each child in turn has property grand-children mapped as sorted map(sorted=natural), hibernate throws an below exception. <b>When merging by method saveOrUpdateCopy() in Hibernate2.1, no error happens.<b> If structure is only parent -> children, no error happens too. When I try debugging into hibernate code, the grand-chilren property is null, instead of return a new TreeMap(sorted), a new HashMap is returned. mapping file: <hibernate-mapping package="dummy"> <!-- parent --> <class lazy="true" name="Parent" table="parent"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <map name="children" lazy="true" inverse="false" cascade="all-delete-orphan" sort="natural"> <key column="parent_id" /> <index column="orders" type="java.lang.Integer" /> <one-to-many class="Child" /> </map> </class> <!-- child --> <class lazy="true" name="Child" table="child"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <property name="order" column="orders" type="java.lang.Integer" /> <many-to-one name="parent" class="Parent" column="parent_id" /> <map name="children" lazy="true" inverse="false" cascade="all-delete-orphan" sort="natural"> <key column="parent_id" /> <index column="orders" type="java.lang.Integer" /> <one-to-many class="GrandChild" /> </map> </class> <!-- grand child --> <class lazy="true" name="GrandChild" table="grand_child"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <many-to-one name="parent" class="Child" column="parent_id" /> <property name="order" column="orders" type="java.lang.Integer" /> </class> </hibernate-mapping> test case: public void testMerge() { Parent parent = new Parent("parent name", null); Long id = (Long) save(parent); parent = (Parent) load(Parent.class, id); restartSession(); Child child = new Child("child name",null, null, null); GrandChild grandChild = new GrandChild("grand child name", null,null); child.addGrandChild(grandChild); parent.addChild(child); Parent parent1 = (Parent) hibSess.get(Parent.class, id); beginTrans(); //cannot call hibSess.update(parent) because instance with the same id parent1 was loaded already hibSess.merge(parent);//error commit(); } trace: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of dummy.Child.setChildren at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:198) at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:168) at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2922) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:247) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:149) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:104) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:492) at org.hibernate.engine.Cascades$6.cascade(Cascades.java:175) at org.hibernate.engine.Cascades.cascade(Cascades.java:721) at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860) at org.hibernate.engine.Cascades.cascade(Cascades.java:739) at org.hibernate.engine.Cascades.cascade(Cascades.java:817) at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:263) at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:222) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:102) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:54) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:483) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:487) at dummy.TestMerge.testMerge(TestMerge.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) Caused by: net.sf.cglib.beans.BulkBeanException at dummy.Child$$BulkBeanByCGLIB$$bd203ea1.setPropertyValues(<generated>) at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:195) ... 31 more Caused by: java.lang.ClassCastException ... 33 more

    Hibernate JIRA | 1 decade ago | Nguyen Hau Giang
    org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of dummy.Child.setChildren
  2. 0

    When merging an entity parent that has property children mapped as sorted map(sorted=natural), each child in turn has property grand-children mapped as sorted map(sorted=natural), hibernate throws an below exception. <b>When merging by method saveOrUpdateCopy() in Hibernate2.1, no error happens.<b> If structure is only parent -> children, no error happens too. When I try debugging into hibernate code, the grand-chilren property is null, instead of return a new TreeMap(sorted), a new HashMap is returned. mapping file: <hibernate-mapping package="dummy"> <!-- parent --> <class lazy="true" name="Parent" table="parent"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <map name="children" lazy="true" inverse="false" cascade="all-delete-orphan" sort="natural"> <key column="parent_id" /> <index column="orders" type="java.lang.Integer" /> <one-to-many class="Child" /> </map> </class> <!-- child --> <class lazy="true" name="Child" table="child"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <property name="order" column="orders" type="java.lang.Integer" /> <many-to-one name="parent" class="Parent" column="parent_id" /> <map name="children" lazy="true" inverse="false" cascade="all-delete-orphan" sort="natural"> <key column="parent_id" /> <index column="orders" type="java.lang.Integer" /> <one-to-many class="GrandChild" /> </map> </class> <!-- grand child --> <class lazy="true" name="GrandChild" table="grand_child"> <id name="id" type="java.lang.Long" column="ID"> <generator class="native" /> </id> <property name="name" column="name" type="java.lang.String" /> <many-to-one name="parent" class="Child" column="parent_id" /> <property name="order" column="orders" type="java.lang.Integer" /> </class> </hibernate-mapping> test case: public void testMerge() { Parent parent = new Parent("parent name", null); Long id = (Long) save(parent); parent = (Parent) load(Parent.class, id); restartSession(); Child child = new Child("child name",null, null, null); GrandChild grandChild = new GrandChild("grand child name", null,null); child.addGrandChild(grandChild); parent.addChild(child); Parent parent1 = (Parent) hibSess.get(Parent.class, id); beginTrans(); //cannot call hibSess.update(parent) because instance with the same id parent1 was loaded already hibSess.merge(parent);//error commit(); } trace: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of dummy.Child.setChildren at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:198) at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:168) at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2922) at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:247) at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:149) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:104) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:492) at org.hibernate.engine.Cascades$6.cascade(Cascades.java:175) at org.hibernate.engine.Cascades.cascade(Cascades.java:721) at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860) at org.hibernate.engine.Cascades.cascade(Cascades.java:739) at org.hibernate.engine.Cascades.cascade(Cascades.java:817) at org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:263) at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:222) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:102) at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:54) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:483) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:487) at dummy.TestMerge.testMerge(TestMerge.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186) Caused by: net.sf.cglib.beans.BulkBeanException at dummy.Child$$BulkBeanByCGLIB$$bd203ea1.setPropertyValues(<generated>) at org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:195) ... 31 more Caused by: java.lang.ClassCastException ... 33 more

    Hibernate JIRA | 1 decade ago | Nguyen Hau Giang
    org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of dummy.Child.setChildren

    Root Cause Analysis

    1. java.lang.ClassCastException

      No message provided

      at dummy.Child$$BulkBeanByCGLIB$$bd203ea1.setPropertyValues()
    2. dummy
      Child$$BulkBeanByCGLIB$$bd203ea1.setPropertyValues
      1. dummy.Child$$BulkBeanByCGLIB$$bd203ea1.setPropertyValues(<generated>)
      1 frame
    3. Hibernate
      BasicEntityPersister.setPropertyValues
      1. org.hibernate.tuple.PojoTuplizer.setPropertyValuesWithOptimizer(PojoTuplizer.java:195)
      2. org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:168)
      3. org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2922)
      3 frames
    4. Hibernate
      SessionImpl.merge
      1. org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:247)
      2. org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:149)
      3. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:104)
      4. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:492)
      4 frames
    5. Hibernate
      Cascades.cascade
      1. org.hibernate.engine.Cascades$6.cascade(Cascades.java:175)
      2. org.hibernate.engine.Cascades.cascade(Cascades.java:721)
      3. org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:860)
      4. org.hibernate.engine.Cascades.cascade(Cascades.java:739)
      5. org.hibernate.engine.Cascades.cascade(Cascades.java:817)
      5 frames
    6. Hibernate
      SessionImpl.merge
      1. org.hibernate.event.def.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:263)
      2. org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:222)
      3. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:102)
      4. org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:54)
      5. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:483)
      6. org.hibernate.impl.SessionImpl.merge(SessionImpl.java:487)
      6 frames
    7. dummy
      TestMerge.testMerge
      1. dummy.TestMerge.testMerge(TestMerge.java:34)
      1 frame
    8. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:324)
      4 frames
    9. JUnit
      TestCase.run
      1. junit.framework.TestCase.runTest(TestCase.java:154)
      2. junit.framework.TestCase.runBare(TestCase.java:127)
      3. junit.framework.TestResult$1.protect(TestResult.java:106)
      4. junit.framework.TestResult.runProtected(TestResult.java:124)
      5. junit.framework.TestResult.run(TestResult.java:109)
      6. junit.framework.TestCase.run(TestCase.java:118)
      6 frames
    10. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
      3 frames