-->
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.  [ 1 post ] 
Author Message
 Post subject: illegally attempted to associate a proxy with 2 open Session
PostPosted: Fri Aug 29, 2008 7:11 pm 
Newbie

Joined: Fri Aug 29, 2008 5:46 pm
Posts: 1
Hibernate: version 3 (hibernate3.jar)
DB: mysql5.0

Problem: illegally attempted to associate a proxy with two open Sessions


I'm trying to update a table in the database using the session and I get the exception "org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions"
In each of my class I use a getSession() from a utility class called HibernateUtil to get session object. The getSession() method is like this:

public static Session getSession() {
if (_sessionFactory == null) {
_sessionFactory = new Configuration().configure().buildSessionFactory();
}
Session session = null;
try {
session = _sessionFactory.getCurrentSession();
} catch (HibernateException e) {
session = _sessionFactory.openSession();
}
return session;
}


The code where the exception is thrown is below, the exception occurs when the "s.update(inNode);" line is executed.

private void updateCostValue(Node inNode, BigDecimal costValue)
{
Cost tempCost;
tempCost = inNode.getnodeCost();
Transaction tr = s.beginTransaction();
try {
s.setFlushMode(FlushMode.ALWAYS);
if(tempCost == null)
{
tempCost = new Cost();
tempCost.setnonWeightedEstimatedCost(costValue);
s.save(tempCost);
HibernateUtil.commitSession(s);
// tried s.evict(inNode); s.merge(inNode); at this line
//looks like inNode is associted with other session
inNode.setnodeCost(tempCost);


s.update(inNode);
}
else {
tempCost.setnonWeightedEstimatedCost(costValue);
s.saveOrUpdate(tempCost);
}

tr.commit();
} catch(Exception e) {
tr.rollback();
e.printStackTrace();
}
HibernateUtil.commitSession(s);
}

Obviously, from the message I interpret that there are 2 active sessions which is a bad thing ofcourse, but I dont see how thats possible, as far as I know, I'm using the same session object? Anyone else has faced this problem? I found plenty of mention of this problem on google but none of the posted solutions helped me, so guys! throw some ideas my way!

The stacktrace is below:


Exception StackTrace
org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions
at org.hibernate.proxy.AbstractLazyInitializer.setSession(AbstractLazyInitializer.java:68)
at org.hibernate.engine.PersistenceContext.reassociateProxy(PersistenceContext.java:520)
at org.hibernate.engine.PersistenceContext.unproxyAndReassociate(PersistenceContext.java:565)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:65)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:490)
at org.sjsu.edu.business.model.EstimatedCostManager.updateCostValue(EstimatedCostManager.java:163)
at org.sjsu.edu.business.model.EstimatedCostManager.updateLeafNodeCost(EstimatedCostManager.java:139)
at org.sjsu.edu.business.model.EstimatedCostManager.computeSECSICCost(EstimatedCostManager.java:197)
at org.sjsu.edu.presentation.EstimatedCostDisplay.actionPerformed(EstimatedCostDisplay.java:368)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1766)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


Thanks,
Praveen


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

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.