-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Illegal attempt to associate a collectionwithtwoopensessions
PostPosted: Wed Aug 13, 2008 4:22 pm 
Newbie

Joined: Wed Aug 13, 2008 3:51 pm
Posts: 3
When I run my application with single thread, it is going fine. When I am testing the same application with multiple users using Load Runner for performance testing, I am getting the following error.

My Sample code is as follows:

saveItems()
{
session = HibernateUtil.getSessionFactory().openSession();
session.setFlushMode(FlushMode.MANUAL);
tx = session.beginTransaction();
//delete the old entries from the database.
List<Item> olditems = dao.findCurrent(account);
for (int i = 0; i < oldItems.size(); i++) {
session.lock(oldItems.get(i), LockMode.UPGRADE);
session.delete(oldItems.get(i));
}
//insert the new entries into the database.
List<Item> newItems = dao.findCurrent(account);

for (int i = 0; i < newItems.size(); i++) {
session.saveOrUpdate(newItems (i));
}
session.flush();
tx.commit();
}

My mapping file is as follows: My item has a mapping file with the child element.

<class name="com.sample.Item" table="item_tbl">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" length="45"/>
<property name="updateDateTime" column="last_modified"/>
<list name="subitems" cascade="all">
<key column="item_id"/>
<index column="row_num"/>
<one-to-many class="com.sample.SubItem"/>
</list>
</class>

org.hibernate.HibernateException: Illegal attempt to associate a collection with
two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSessi
on(AbstractPersistentCollection.java:410)
at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVis
itor.java:40)
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(A
bstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:
123)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDe
leteEventListener.java:90)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDe
leteEventListener.java:49)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)

Please help me in knowing why this exception is coming. Any pointers towards this error would be greatly appreciated.

Thanks In Advance,
Best Regards,
dp


Top
 Profile  
 
 Post subject: Problem with my code
PostPosted: Tue Aug 19, 2008 6:33 am 
Newbie

Joined: Wed Aug 13, 2008 3:51 pm
Posts: 3
Hi,

My Dao class was singleton and setting the session to the dao class was giving the problem.

Once the dao.setSession(session);

I was setting the session and doing the deletion of the table items and subitems and inserting the item and subitem.

But as the Dao class is singleton, when another request comes, it is creating the session and doing the dao.setSession(session), there by overriding the existing session.

That's the reason my list was giving me the problem, that

Illegal attempt to associate the same collection with different open sessions.

Hope this helps.

Best Regards,
Durga


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.