-->
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: problem persisting children of a parent object in Thread
PostPosted: Tue Jun 12, 2007 10:02 am 
Newbie

Joined: Thu Jun 07, 2007 8:07 am
Posts: 2
Hibernate version: 3.2
Name and version of the database you are using: hsqldb (latest)

I've got a ThreadImpl class that adds a child to a parent. The mapping indicates a cascade for the list of children so no need to save/update the Child itself. As requests to add children come in, a new ThreadImpl is created and added to a queue to run one at a time. Here are the steps in the run method and a utility method to get the Container, I've included code where it is important.
Code:
Container getContainer() {
Session s = null;
   try {
      s = hibernateUtil.getSession();

                // query for container (it returns the Container correctly)

                hibernateUtil.endSession();
   } catch (Exception ex) {
      ex.printStackTrace();
   } finally {
      hibernateUtil.endSession();
   }
}


Now the run:

Code:
public void run() {
  Container container = getContainer()

  Child child = new Child()
  container.addChild(child)

  session = null;
   try {
      session = hibernateUtil.getSession();
      Transaction transaction = session.beginTransaction();
      try {
         session.saveOrUpdate(container);
         transaction.commit();
      } catch (Exception e) {
         transaction.rollback();
      }
       hibernateUtil.endSession();
   } catch (Exception hex) {
      hex.printStackTrace();
      if (session.isOpen())
         hibernateUtil.endSession();
   }
}


I guess I should also state that hibernateUtil has the Session object which it opens from the SessionFactory and returns, and the endSession method closes the session if it is open.

It correctly stores the first Child when I run this, but fails to store the children created and added in following ThreadImpls. I've tried adding a merge(container) before the saveOrUpdate but that doesn't seem to have any affect. Also, there are no exception thrown to indicate that anything is amiss. I'm assuming this is some sort of container object state issue, but I can't figure it out.

thanks for any input.

jason


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.