nordborg wrote:
Just add the A's to the collection in B and then persist B. Hibernate will figure everything out automatically.
Thanks for the quick reply. That would work just for this case. But in general (that is, without assuming everything is done in one transaction), say we have another class C that has a collection of A's as well. (I actually do). The difference is that B owns A's but C doesn't. e.g.
Code:
class B {
@OneToMany(cascade = ALL)
Set<A> ...;
}
class C {
@OneToMany
Set<A> ...; // without cascade
}
I'm doing the following:
create B, add A to B, persist
some time later
an instance of C needs to have that A I just created.
The problem is the same as before: I can't obtain a fresh version of A because both A and B are only identified uniquely by their own primary keys.