-->
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: Two open session Exception
PostPosted: Sun May 16, 2010 4:18 pm 
Newbie

Joined: Sun May 16, 2010 4:00 pm
Posts: 1
Hello,
I'm getting the following exception after I try to add an one-to-many list to the Categories
I have Categories > MainTopics > SubTopics > Comments tables.
Categories should have one-to-many Main Topics
MainTopics should have one-to-many SubTopics ect..

When I deleted a category I want to delete all related MainTopics automatically.
If I add the following list entry to the Categories table I get the following exception.
If I delete the lines from the Categories.hbm.xml every thing works okey but I can not cascade :-)

Thanksin advice..
Categories.hbm.xml
Code:
   
        <list name="mainTopics" cascade="all">
            <key column="CATAGORY_ID"/>
            <index column="upCatagoryId"/>
            <one-to-many class="MainTopics"/>
        </list>

Categories Class:
Code:
private Long catagoryId;
private List<MainTopics> mainTopics;

MainTopics Class:
Code:
private Long mainTopicId;
private Catagories upCatagoryId;
private List<SubTopics> subTopics;

The working server side code that throws exception:
Code:
   Boolean flag=true;
      Session session = BitNotesHibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();
      try{
         session.delete(catagory);
//exception throws here
//I want to implement a model that automatically deletes sub hierarchy when a category deleted..
      }catch(Exception ex){
         flag=false;
         ex.printStackTrace();

      }
      session.close();
      return flag;

Exception:
Code:
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions: [com.bitnotes.domain.Catagories.mainTopics#7]
   at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:437)
   at org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:66)
   at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:124)
   at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:84)
   at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:78)
   at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:146)
   at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:123)
   at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
   at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:793)
   at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:771)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
   at $Proxy20.delete(Unknown Source)
   at com.bitnotes.server.UserOperationsServiceImpl.removeCategory(UserOperationsServiceImpl.java:358)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:616)
   at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:174)
   at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
   at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
   at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
   at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
   at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
   at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
   at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
   at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
   at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
   at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
   at org.mortbay.jetty.Server.handle(Server.java:324)
   at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
   at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
   at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
   at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
   at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
   at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
   at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)


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.