Michael Bayer wrote:
is the exception thrown upon deleting the object, or upon saving a list that contains a deleted object? I can add an exception for the latter pretty easily (probably should).

It happens on session.flush() in Hibernate, which is session.commit() in 
SQLAlchemy. The collection may or may not be dirty, which means you'd need to 
keep track of object/collection mappings (I'm pretty sure Hibernate is doing 
this since they're detecting when a child has been deleted but not removed from 
an association collection). An exception would be better than silently deleting 
the item while leaving it in collections.

The former requires that I track all the lists every object belongs to. what is the reason hibernate doesnt remove deleted items automatically ?

It's strange... I can't find a really good reason. I scanned all of the 
pertinent sections of the Hibernate reference documentation, and they cover 
every possible scenario except this one (it seems like it was intentionally 
left out just to confuse people out or something). The docs always advise to 
manage children in a parent/child relationship through the collection attached 
to the parent (i.e. always do parent.remove(child)).

The best thing I can come up with is that Hibernate would allow you to do 
something like this:

parent.children.remove(child)
session.commit() # child is deleted
parent.children.append(child)
session.commit() # child is re-inserted

Then if you do this

child = parent.children[0]
session.delete(child)

even though the child was deleted it looks like it is being re-inserted because 
it is still in parent.children. Even after all that though, I still can't quite 
see why? It seems like the Hibernate developers are trying to force the user to 
be explicit about deleting children by breaking the association as well as 
deleting the child (in fact, with the correct mapping configuration the child 
can be deleted automatically by removing it from parent.children...go figure).

i can see below theyre expecting you to do it yourself but i wonder if the same feature request has been made to them.

Oh I'm sure it has, many times. However, Gavin and his gang get a big arrogant 
sometimes. They just blow people off with RTFM (because they know better...and 
most of the time they do).

The more I think about it the more I lean toward having it removed from the 
parent collection after the child is deleted (when the session is committed, 
not before). session.delete(child) is explicit enough for me. And if for some 
reason someone wants a list to retain deleted items they could do something 
like this:

children = list(parent.children).

Something just keeps nagging at me that there's a good reason the Hibernate 
guys did it the way they did... What do you think?

~ Daniel


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to