Ok - that surprises me a little :)
I understand that if the collection instance is replaced then hibernate can
not have any clue on what to do (or maybe it could load the existing
relationship from the db, and do an compare ? Or is this to complex/heavy
?). But I had somewhat expected (silly me :) that if the collection was one
of the hibernate'ones then hibernate would "trust" them to be "correct" and
tracked.

s = sf.createSession();
Cat c = new Cat("Morris");
p.getFriends().add(new Cat("Gustav"));
Cat sabrina = new Cat("Sabrina")
p.getFriends().add(sabrina);
p.getFriends().add(new Cat("Bond"));
s.save...(save of c and all its siblings)
s.flush();
s.close();

p.getFriends().remove(sabrina); // I had expected that the hibernateSet here
would track this removal....

s = sf.createSession();
// will this result in a delete of all cat-to-friends pairs in the
many-to-many table ?
// and afterwards result in insertion of the siblings left in the
getFriends() set ?
s.saveOrUpdate(p);
s.flush();
s.close();

And if the friends relationship (many-to-many) would have been children
instead (many-to-one), then Gustav, Sabrina and Bond's
parent key woud have been nulled (via an update) and then afterwards Gustav
and Bond's would be again updated, right ?

Does this makes sense :)

/max


----- Original Message -----
From: "Gavin King" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 18, 2003 11:36 PM
Subject: Re: [Hibernate] collections (in one-to-many, many-to-one, etc..)


>
> Inside a Session, Hibernate keeps a snapshot of the original state
> of a collection and so can do removals/additions individually.
>
> However, an object that came into the session via a call to update()
> may have had all kind of things done to it (a PersistentCollection
> completely replaced with a transient Collectin, for example). So we
> can't really have been tracking changes. In this case Hibernate
> simply removes all the existing rows using a single DELETE or
> UPDATE and then recreates the whole collection, based upon the new
> state of the object that was passed to update().
>
> Think of update() as "trash whatever was there and use this instead".
> OTOH, load() followed by flush() means "grab the existing state and
> then carefully make any necessary adjustments".
>
>
> > How does Hibernate decide/track how to delete, update, insert tuples
based
> > on what the user has added and/or removed in the sets/lists representing
> > many-to-one and many-to-many mappings ?
> >
> > (the question just came to my mind when i saw:  "P.S. Hibernate is *not*
> > tracking which objects were removed from the collection (also a Good
> > Thing)." - and I came to think: Ok, but then how does it decide to do a
> > delete of something if it does not track deletions :)
> > (I guess there are an simple and an more advanced explanation - I like
them
> > both :)
>
>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by: Thawte.com - A 128-bit supercerts will
> allow you to extend the highest allowed 128 bit encryption to all your
> clients even if they use browsers that are limited to 40 bit encryption.
> Get a guide here:http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0030en
> _______________________________________________
> hibernate-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>



-------------------------------------------------------
This SF.NET email is sponsored by: FREE  SSL Guide from Thawte
are you planning your Web Server Security? Click here to get a FREE
Thawte SSL guide and find the answers to all your  SSL security issues.
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to