net.sf.hibernate.AssertionFailure: Hibernate has a bug processing collections

Hibernate JIRA | Kelley Stover | 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

    Class A has a many to many Set reference to Class B Class B has a many to many Set reference to Class A Class C is a subclass of A lazy loading is enabled The classes A, B, C use custom persisters. The sets use custom collection persisters. When updating a data member of class B (migrationStatus), We see the exception shown below in the stack trace. This bug is not seen when the contents of the set are forced to load by iterating the set, eg: Set s = b.getACollection(); for (Iterator it = s.iterator(); it.hasNext();) { A a = (A)it.next(); } Hibernate mapping files for the two classes look like: (note uses the hibernate-mapping-2.0.dtd in the patch submitted with HB-419) <class name="sample.A" schema="adm" table="SAMPLE_A" persister="sample.APersister"> <meta attribute="implements">sample.hibernate.IAuditable</meta> <id name="id" type="int" unsaved-value="null"> <column name="sample_a_id" length="32"/> <generator class="sequence"> <param name="sequence">sample_a_id_seq</param> </generator> </id> <discriminator column="discriminator_column" type="string" force="false" /> <set name="childrenSites" inverse="true" lazy="true" cascade="all-delete-orphan"> <key column="parent_site_id"/> <one-to-many class="sample.A"/> </set> <many-to-one name="parent" column="parent_a_id" cascade="none" class="sample.A"/> <property name="aName" column="a_name" type="java.lang.String"/> <set name="properties" table="A_PROPERTY" inverse="true" lazy="true" cascade="all-delete-orphan"> <key column="sample_a_id" /> <one-to-many class="sample.Property" /> </set> <set name="bCollection" table="SAMPLE_AB_ASSOC" inverse="false" lazy="true" cascade="none" persister="sample.ABCollectionPersister"> <key column="SAMPLE_A_ID"/> <many-to-many column="SAMPLE_B_ID" class="sample.B"/> </set> <subclass name="sample.C" persister="sample.CPersister"> <property name="cURI" column="c_uri" type="string" unique="true"/> </subclass> </class> <class name="sample.B" schema="adm" table="SAMPLE_B" persister="sample.BPersister"> <meta attribute="implements">sample.hibernate.IAuditable</meta> <id name="primaryKey" type="java.lang.Integer" unsaved-value="null"> <column name="sample_b_id" length="16"/> <generator class="sequence"> <param name="sequence">sample_b_id_seq</param> </generator> </id> <property name="bId" type="java.lang.String" length="16" not-null="true" column="building_id"/> <property name="bName" type="java.lang.String" length="35" not-null="false" column="b_name"/> <property name="migrationStatus" type="java.lang.Character" length="1" not-null="false" column="migration_status" /> <set name="aCollection" table="SAMPLE_AB_ASSOC" inverse="true" lazy="true" cascade="none" persister="sample.ABCollectionPersister"> <key column="sample_B_ID"/> <many-to-many column="sample_A_ID" class="sample.A"/> </set> </class> Stack Trace: net.sf.hibernate.AssertionFailure: Hibernate has a bug processing collections at net.sf.hibernate.impl.SessionImpl$CollectionEntry.postFlush(SessionImpl.java:365) at net.sf.hibernate.impl.SessionImpl.postFlush(SessionImpl.java:2800) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2205) at sample.ABAssocTest.doUpdateAWithAssocB(ABAssocTest.java:95) at sample.ABAssocTest.testUpdateOnRealDataCase(ABAssocTest.java:55) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

    Hibernate JIRA | 1 decade ago | Kelley Stover
    net.sf.hibernate.AssertionFailure: Hibernate has a bug processing collections
  2. 0

    Class A has a many to many Set reference to Class B Class B has a many to many Set reference to Class A Class C is a subclass of A lazy loading is enabled The classes A, B, C use custom persisters. The sets use custom collection persisters. When updating a data member of class B (migrationStatus), We see the exception shown below in the stack trace. This bug is not seen when the contents of the set are forced to load by iterating the set, eg: Set s = b.getACollection(); for (Iterator it = s.iterator(); it.hasNext();) { A a = (A)it.next(); } Hibernate mapping files for the two classes look like: (note uses the hibernate-mapping-2.0.dtd in the patch submitted with HB-419) <class name="sample.A" schema="adm" table="SAMPLE_A" persister="sample.APersister"> <meta attribute="implements">sample.hibernate.IAuditable</meta> <id name="id" type="int" unsaved-value="null"> <column name="sample_a_id" length="32"/> <generator class="sequence"> <param name="sequence">sample_a_id_seq</param> </generator> </id> <discriminator column="discriminator_column" type="string" force="false" /> <set name="childrenSites" inverse="true" lazy="true" cascade="all-delete-orphan"> <key column="parent_site_id"/> <one-to-many class="sample.A"/> </set> <many-to-one name="parent" column="parent_a_id" cascade="none" class="sample.A"/> <property name="aName" column="a_name" type="java.lang.String"/> <set name="properties" table="A_PROPERTY" inverse="true" lazy="true" cascade="all-delete-orphan"> <key column="sample_a_id" /> <one-to-many class="sample.Property" /> </set> <set name="bCollection" table="SAMPLE_AB_ASSOC" inverse="false" lazy="true" cascade="none" persister="sample.ABCollectionPersister"> <key column="SAMPLE_A_ID"/> <many-to-many column="SAMPLE_B_ID" class="sample.B"/> </set> <subclass name="sample.C" persister="sample.CPersister"> <property name="cURI" column="c_uri" type="string" unique="true"/> </subclass> </class> <class name="sample.B" schema="adm" table="SAMPLE_B" persister="sample.BPersister"> <meta attribute="implements">sample.hibernate.IAuditable</meta> <id name="primaryKey" type="java.lang.Integer" unsaved-value="null"> <column name="sample_b_id" length="16"/> <generator class="sequence"> <param name="sequence">sample_b_id_seq</param> </generator> </id> <property name="bId" type="java.lang.String" length="16" not-null="true" column="building_id"/> <property name="bName" type="java.lang.String" length="35" not-null="false" column="b_name"/> <property name="migrationStatus" type="java.lang.Character" length="1" not-null="false" column="migration_status" /> <set name="aCollection" table="SAMPLE_AB_ASSOC" inverse="true" lazy="true" cascade="none" persister="sample.ABCollectionPersister"> <key column="sample_B_ID"/> <many-to-many column="sample_A_ID" class="sample.A"/> </set> </class> Stack Trace: net.sf.hibernate.AssertionFailure: Hibernate has a bug processing collections at net.sf.hibernate.impl.SessionImpl$CollectionEntry.postFlush(SessionImpl.java:365) at net.sf.hibernate.impl.SessionImpl.postFlush(SessionImpl.java:2800) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2205) at sample.ABAssocTest.doUpdateAWithAssocB(ABAssocTest.java:95) at sample.ABAssocTest.testUpdateOnRealDataCase(ABAssocTest.java:55) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

    Hibernate JIRA | 1 decade ago | Kelley Stover
    net.sf.hibernate.AssertionFailure: Hibernate has a bug processing collections
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Hibernate Community • View topic - AssertionFailure: possible nonthreadsafe access to session

    hibernate.org | 7 months ago
    net.sf.hibernate.AssertionFailure: possible nonthreadsafe access to session
  5. 0

    I am getting an AssertionFailure - cannot cache a reference to an object with a null id when I try to do an update. Here is the sample code - NB: This has been working fine for me in hibernate versions 2.0 - 2.03 I have the following two mappings <class name="Customer" table="customers" polymorphism="explicit"> <cache usage="read-write"/> <id name="id" unsaved-value="0"> <generator class="sequence"> <param name="sequence">customers_id_seq</param> </generator> </id> <property name="postcode"/> <many-to-one name="csOwner" class="Employee" column="cs_owner" /> </class> and <class name="Employee" table="staff"> <id name="id"> <generator class="sequence"> <param name="sequence">staff_id_seq</param> </generator> </id> <property name="name"/> </class> the following main() throws the exception Session session = null; Customer customer = null; SessionFactory factory = null; try { // build factory factory = new Configuration().configure().buildSessionFactory(); System.out.println("Starting first session"); // first session gets customer instance session = factory.openSession(); customer = (Customer) session.load(Customer.class, new Long(1275)); System.out.println("Loaded customer " + customer.getId() + " has owner " + customer.getCsOwner().getId()); session.flush(); session.connection().commit(); session.close(); System.out.println("Updating address field"); // update a field customer.setPostcode("TESTING"); System.out.println("Starting second session"); // second session persists update session = factory.openSession(); session.update(customer); session.flush(); session.connection().commit(); session.close(); System.out.println("Finished"); factory.close(); } catch (Exception ex){ ex.printStackTrace(); } finally { if(session!=null)session.close(); if(factory!=null)factory.close(); System.exit(0); } If i remove the cache entry in the customer mapping everything is OK, but other wise i get net.sf.hibernate.AssertionFailure: cannot cache a reference to an object with a null id at net.sf.hibernate.type.EntityType.disassemble(EntityType.java:89) at net.sf.hibernate.impl.CacheEntry.disassemble(CacheEntry.java:36) at net.sf.hibernate.impl.CacheEntry.<init>(CacheEntry.java:27) at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:42) at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278) at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235) at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178) at com.lab.model.HibBug.main(HibBug.java:46)

    Hibernate JIRA | 1 decade ago | tekno
    net.sf.hibernate.AssertionFailure: cannot cache a reference to an object with a null id

    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. net.sf.hibernate.AssertionFailure

      Hibernate has a bug processing collections

      at net.sf.hibernate.impl.SessionImpl$CollectionEntry.postFlush()
    2. net.sf.hibernate
      SessionImpl.flush
      1. net.sf.hibernate.impl.SessionImpl$CollectionEntry.postFlush(SessionImpl.java:365)
      2. net.sf.hibernate.impl.SessionImpl.postFlush(SessionImpl.java:2800)
      3. net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2205)
      3 frames
    3. Java EE Connector Architecture API Specification
      ABAssocTest.testUpdateOnRealDataCase
      1. sample.ABAssocTest.doUpdateAWithAssocB(ABAssocTest.java:95)
      2. sample.ABAssocTest.testUpdateOnRealDataCase(ABAssocTest.java:55)
      2 frames
    4. 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
    5. JUnit
      TestSuite.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)
      7. junit.framework.TestSuite.runTest(TestSuite.java:208)
      8. junit.framework.TestSuite.run(TestSuite.java:203)
      8 frames
    6. JUnit3 Runner
      RemoteTestRunner.main
      1. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
      2. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
      3. org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)
      3 frames