title: Illegal attempt to associate a collection with two open sessions
body: <p>I'm trying to add a pojo to a collection in another pojo. I'm sure I'm making a really stupid mistake somewhere along the lines but I can't figure out how to solve it.</p>
  
  <p>I have a pojo LookupTable which contains a list of Columns:</p>
  
  <pre><code>public class LookupTable {
    private long id;
    // More properties go here...
    private List&lt;Column&gt; columns;
  
    public void addColumn(Column column) {
      this.columns.add(column);
    }
  
    // More methods go here...
  }
  </code></pre>
  
  <p>In my hibernate configuration I have:</p>
  
  <pre><code>&lt;class name="LookupTable" table="ARR_LOOKUP_TABLE"&gt;
    &lt;id name="id" column="ID"&gt;
      &lt;generator class="native"/&gt;
    &lt;/id&gt;
    &lt;!-- Some properties here --&gt;
    &lt;bag name="columns" cascade="all,delete-orphan" access="field"&gt;
      &lt;key column="LOOKUP_TABLE" not-null="true"/&gt;
      &lt;one-to-many class="Column"/&gt;
    &lt;/bag&gt;
  &lt;/class&gt;
  
  &lt;class name="Column" table="ARR_LOOKUP_COLUMN"&gt;
    &lt;id name="id" column="ID"&gt;
      &lt;generator class="native"/&gt;
    &lt;/id&gt;
    &lt;!-- Some properties here --&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>In my Spring config file I have:</p>
  
  <pre><code>&lt;tx:advice id="txAdvice" transaction-manager="txManager"&gt;
    &lt;tx:attributes&gt;
      &lt;tx:method name="*" propagation="REQUIRED"/&gt;
    &lt;/tx:attributes&gt;
  &lt;/tx:advice&gt;
  &lt;aop:config&gt;
    &lt;aop:pointcut id="managers" expression="execution(public * com.foo.*Manager.*(..))"/&gt;
    &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="managers"/&gt;
  &lt;/aop:config&gt;
  </code></pre>
  
  <p>And finally the code where it all fails within my manager class (com.foo.LookupTableManager):</p>
  
  <pre><code>public void addColumnToTable(Column column, long tableId) {
    LookupTable lookupTable = this.lookupTableDao.findById(tableId);
    lookupTable.addColumn(column);
    this.lookupTableDao.saveOrUpdate(lookupTable);
  }
  </code></pre>
  
  <p>The variable lookupTableDao here refers to a simple DAO class which extends HibernateDaoSupport.</p>
  
  <p>The error I get is:</p>
  
  <pre><code>org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
    at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
    at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:43)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
    at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
    at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:223)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:89)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
    at com.foo.AbstractDao.saveOrUpdate(AbstractDao.java:29)
    at com.foo.LookupTableManager.addColumnToTable(LookupTableManager.java:338)
  ... etc ...
  </code></pre>
  
  <p>OK, I understand the basic message I'm getting. But what I don't understand is where I get the second session.... Can anyone help me with this?</p>
  
  <p>I'm using Hibernate 3.2.6.ga, Spring 2.5.5 and Tomcat 6.0</p>