gavin wrote:
I dunno, sounds like you did something "funny" in your Java code, like accessed the collection during the cascade. But I can't see any code, so I've no idea.
Well *that* can easily be changed :-)
Though I am quite certain I didn't do any funny things with it. I created the new set, committed the Transaction, and only then continued with my application. And I am 100% certain that there was no other thread doing anything with it either.
The code:
Code:
try
{
t = DAOTransaction.beginTransaction(); // This is just a wrapped Hibernate Transaction, commit() and rollback() go straight through to the Hibernate Transaction object
Long answerSetId = (Long) dform.get("answerSetId");
// this loads the parent AnswerSet:
AnswerSet aset = t.getAnswerDAO().getAnswerSet(answerSetId);
User u = (User) req.getSession().getAttribute("user");
String type = (String) dform.get("type");
// check to see whether the current user is allowed to do this
if (aset.getParentQuestion().getPoll().checkEditPrivileges(u))
{
if ("single".equals(type))
{
// create a new single Answer, this has always worked
new Answer(aset.getParentQuestion(), aset);
}
else if ("set".equals(type))
{
// create an AnswerSet
new AnswerSet(aset.getParentQuestion(), aset);
}
// everything works fine up to here!
// if I created an AnswerSet, this call bombed:
t.commit();
}
else
{ // No rights, no change: rollback
t.rollback();
}
t = null;
}
catch (DAOException e) // a wrapped hibernate exception
{
if (t != null)
{
t.rollback();
}
log.warn(e);
throw e;
}
// and return to the rest of the webapp. everything else that could happen happens in a new hibernate session
return mapping.findForward("success");
The constructor of AbstractAnswer simply sets the reference fields to parentSet and parentQuestion, and adds the Answer to parentSet, if necessary. That is all done by the time it gets to t.commit(), though.
With the AnswerSet list and the parentSet field sharing a column, the t.commit() call throws the exception mentioned in the original post. Now that they don't share that column any more it works.
It works now, so I am just interested in this out of curiosity, and to understand Hibernate better, because it does seem to me that it is just a workaround. If you think it's not worth investigating more, that's fine, though.
Thanks for your help, even though we users are a pain sometimes, Gavin ;-)
Carl-Eric