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

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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
    via by Nguyen Hau Giang,
  • 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
    via by 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 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
    No Bugmate found.