I hate to bother you with this again but I've tried every possible option I can think of, poured through the debug logs, traced code and unless I'm missing something, I can't see a way to make this work. I'm sure I'm missing one small item that will make this work or else I misunderstand how cascade works.
The code I started with before your reply was:
TheOne to = new TheOne();
to.setMyValue("One Value");
TheMany tm = new TheMany();
tm.setMyValue("Many Value");
HashSet set = new HashSet();
set.add(tm);
to.setTheManys(set);
hibSession.save(to);
If I remove the
to.setTheManys(set);
and replace it with
tm.setTheOne(to);
It only saves TheOne and not TheMany since it when it gets to the cascade method, the child is null.
So my next thought is to try both these segments of code:
to.setTheManys(set);
tm.setTheOne(to);
Then it fails with this exception as Hibernate thinks it already saved TheMany with ID=0 and then tries to do an update. Of course the update fails because there is no row in the database:
ERROR [main] (SessionImpl.java:2375) - Could not synchronize database state with session net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
The only thing I can get to work is shown below. However this seems to defeat the purpose of having a cascade:
TheOne to = new TheOne();
to.setMyValue("Locally the one.");
TheMany tm = new TheMany();
tm.setMyValue("Locally the many.");
tm.setTheOne(to);
s.save(to);
s.save(tm);
Thanks for your help.
_________________ Jon
|