Team,
I've sent this question to persistence alias on Tuesday,
but it never went through. So I'm resending it to both
aliases as I still don't have luck with persistence alias.
Note: Our current implementation cascades with
a1.getBs().add(b1) but this doesn't eliminate
the original concern that ownership rules seem
to contradict the cascade rules.
thanks,
-marina
-------- Original Message --------
Subject: Cascade persist and 1ToMany relationship?
Date: Tue, 22 Nov 2005 10:25:02 -0800
From: Marina Vatkina <marina.vatkina_at_sun.COM>
To: "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>
Team,
I'm a bit confused about the rules for creating a set of related
instances in the same tx and persisting them using CASCADE=ALL
setting. The relationships are bidirectional and FK-based.
Let's say I have A with a collection of 'bs', and B with a property 'a'.
A a1 = new A(...);
B b1 = new B(...);
B b2 = new B(...);
From which side do I need to set relationships to call em.persist(a1)
and see the magic?
If I do it from B (b1.setA(a1)), a1 doesn't know about the related instance
to persist it.
If I do it from A (a1.getBs().add(b1)), then according to the spec, the
relationship
change won't be propagated because the Many side owns the relationship.
If I set it from all sides, what do I gain as I could just persist all of them
separately - it's the same ammount of code?
thanks,
-marina