Hibernate version: 2.1.6
Wrt following thread. Is it true that collection sets are deleted and then reinserted? For me that affects auditing. Deleting a row that hasn't been touched only to re-insert it again causes audit timestamps. Is there a hibernate way to avoid this behavior so that when updating a collection it iterates through the items in the set in the db and the if the object doesn't exist in the transient set a delete will occur from the database and if at the end of the iteration some columns in the collection haven't been found then those rows will be inserted? If there is no such feature in hibernate 2 then how would you suggest implementing the behaviour. Also will this behavior be in hibernate 3.----------------------------------------------
Re: [Hibernate] collections (in one-to-many, many-to-one, etc..)
--------------------------------------------------------------------------------
From: Gavin . King
Subject: Re: [Hibernate] collections (in one-to-many, many-to-one, etc..)
Date: Mon, 20 Jan 2003 02:29:50 +0100 (CET)
--------------------------------------------------------------------------------
The reason we do it this way is to preserve the semantics that update()
*completely*
replaces the existing state. Otherwise, there is the potential for another
transaction to have
come in and added something to the collection. Then after the update() and
flush(), the
state in memory and the state on disk would not be the same (there would be
this
extra row).
I think that this is not a bad way to do things. (It is slow for very large
collections,
however).
"Max Rydahl Andersen"
<[EMAIL PROTECTED]> To: <[EMAIL
PROTECTED]>
Sent by: cc:
[EMAIL PROTECTED] Subject: Re: [Hibernate] collections
(in one-to-many, many-to-one,
eforge.net etc..)
20/01/03 12:27 AM
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/redi ... thaw0030en
> _______________________________________________
> hibernate-devel mailing list
> [EMAIL PROTECTED]
>
https://lists.sourceforge.net/lists/lis ... nate-devel
>