Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding @Transactional causes "collection with cascade="all-delete-orphan" was no longer referenced"
    text
    copied!<p>I am upgrading a working project from Spring2+Hibernate3 to Spring3+Hibernate4. Since HibernateTemplate and HibernateDAOSupport have been retired, I did the following </p> <p>Before (simplified)</p> <pre><code>public List&lt;Object&gt; loadTable(final Class&lt;?&gt; cls) { Session s = getSession(); // was calling the old Spring getSession Criteria c = s.createCriteria(cls); List&lt;Object&gt; objects = c.list(); if (objects == null) { objects = new ArrayList&lt;Object&gt;(); } closeSession(s); return objects; } </code></pre> <p>Now (simplified)</p> <pre><code>@Transactional(propagation=Propagation.REQUIRED) public List&lt;Object&gt; loadTable(final Class&lt;?&gt; cls) { Session s = sessionFactory.getCurrentSession(); Criteria c = s.createCriteria(cls); List&lt;Object&gt; objects = c.list(); if (objects == null) { objects = new ArrayList&lt;Object&gt;(); } return objects; } </code></pre> <p>I also added the transaction annotation declaration to Spring XML and removed this from Hibernate properties</p> <pre><code> "hibernate.current_session_context_class", "org.hibernate.context.ThreadLocalSessionContext" </code></pre> <p>The @Transactional annotation seems to have worked as I see this in the stacktrace </p> <pre><code>at com.database.spring.DatabaseDAOImpl$$EnhancerByCGLIB$$7d20ef95.loadTable(&lt;generated&gt;) </code></pre> <p>During initialization, the changes outlined above seem to work for a few calls to the loadTable function but when it gets around to loading an entity with a parent, I get the "collection with cascade="all-delete-orphan" was no longer referenced" error. Since I have not touched any other code that sets/gets parents or children and am only trying to fix the DAO method, and the query is only doing a sql SELECT, can anyone see why the code got broken?</p> <p>The problem seems similar to <a href="https://stackoverflow.com/questions/2774206/spring-transaction-management-breaks-hibernate-cascade">Spring transaction management breaks hibernate cascade</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload