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