It's not a secret anymore!*
The moose likes Other Application Frameworks and the fly likes Illegal attempt to associate a collection with two open sessions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Illegal attempt to associate a collection with two open sessions" Watch "Illegal attempt to associate a collection with two open sessions" New topic
Author

Illegal attempt to associate a collection with two open sessions

Aadil Pala
Greenhorn

Joined: Nov 01, 2004
Posts: 3
To all Spring/Hibernate Gurus,

I am using the following code(in bold), but I get an exception when i try to delete the data from the sourceDao within the transaction(exception is given below). I even tried copying data to a different list before passing it to the delete method, but it still gives the same exception.

Remember, the copying part is not in the transaction. It only has writing to one database and deleting from the copied database(so read only trxs dont work). Is there a way I could manually detach the list from the first session??

pData = sourceDao.getSourceData(startDate, endDate);

DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.P ROPAGATION_REQUIRED);
TransactionStatus status = this.secTxManager.getTransaction(def);
try{

pageCount = secArchiveDao.archive(pData);
sourceDao.deleteSourceData(pData);
secTxManager.commit(status);
success = true;

} catch (Exception ex)
{
secTxManager.rollback(status);

}



Exception:
org.springframework.orm.hibernate3.HibernateSystem Exception: Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollect ion.setCurrentSession(AbstractPersistentCollection .java:237)
at org.hibernate.event.def.OnUpdateVisitor.processCol lection(OnUpdateVisitor.java:41)
at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEnt ityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.AbstractVisitor.process(Ab stractVisitor.java:129)
at org.hibernate.event.def.DefaultDeleteEventListener .onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.impl.SessionImpl.delete(SessionImpl. java:579)
at org.springframework.orm.hibernate3.HibernateTempla te$26.doInHibernate(HibernateTemplate.java:703)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTempla te.deleteAll(HibernateTemplate.java:699)
at org.tiaa.secarchive.dao.impl.SecProductionCltDAOIm pl.deleteSourceData(SecProductionCltDAOImpl.java:7 6)
at org.tiaa.secarchive.delegate.impl.SecArchiveDelega teImpl.archive(SecArchiveDelegateImpl.java:86)
at org.tiaa.secarchive.schedule.impl.JobImpl.archive( JobImpl.java:328)
at org.tiaa.secarchive.schedule.impl.JobImpl.execute( JobImpl.java:210)
at org.tiaa.secarchive.schedule.impl.DaemonImpl.run(D aemonImpl.java:239)
at java.lang.Thread.run(Thread.java:534)
org.tiaa.j2eeinfra.exception.TiaaRuntimeException: There are no open seeds in the database. New Seeds need to be created !
at org.tiaa.secarchive.schedule.impl.JobImpl.checkSee dsAvailability(JobImpl.java:415)
at org.tiaa.secarchive.schedule.impl.JobImpl.execute( JobImpl.java:80)
at org.tiaa.secarchive.schedule.impl.DaemonImpl.run(D aemonImpl.java:239)
at java.lang.Thread.run(Thread.java:534)

Any help is greatly appreciated:
Thanks
Aadil
Afsheen Fatima
Greenhorn

Joined: Dec 08, 2006
Posts: 1
I am having a similar issue. Have you had any luck fixing this? My requirement is the same as yours. I'm archiving data from live DB to an archive DB.

I would really appreciate your feedback.

Thanks,
~Afsheen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal attempt to associate a collection with two open sessions