On Wed, Mar 4, 2009 at 2:59 PM, Emmanuel Bernard <emmanuel(a)hibernate.org>wrote:
class Address { @ManyToOne Country country;
@ManyToOne State state;
@ManyToMany Set<Person> inhabitants;
}
It generally makes no sense to cascade persist for these three
associations. Even if your app has 80 entities, it's very likely that half
of the associations should not be cascaded :)
Let's take your proposal
PERSIST, DELETE, REFRESH
I REFRESH address and changes on Person are lost, doh!
True. I was on the fence about REFRESH. I think you convinced me.
PERSIST, do I really save an address and expect the person living
there to
be added to the system. Surely not, the person is very likely to have been
built beforehand. Same for Country and State.
Not a problem if County and State are managed, which is likely how you
attach them anyway. It will even work if they are a non-managed entity with
a valid ID. If neither of those are the case, then yes, I want the persist
to add them to the database. That's the whole point of the cascade.
MERGE Do I really want to update a country when an address changes? I
can't
find a system that would do that.
I don't do MERGE, so I don't care.
Cascade has performance consequences. The more cascades the slower
your app
will be at flush time. Especially on applications with a lot of entities.
NONE is a good default, that's why it's the default we have chosen :)
I'm still don't agree. I like PERSIST and DELETE. DELETE can be dangerous,
but it's also extremely convenient.
-Dan
--
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
http://mojavelinux.com
http://mojavelinux.com/seaminaction
NOTE: While I make a strong effort to keep up with my email on a daily
basis, personal or other work matters can sometimes keep me away
from my email. If you contact me, but don't hear back for more than a week,
it is very likely that I am excessively backlogged or the message was
caught in the spam filters. Please don't hesitate to resend a message if
you feel that it did not reach my attention.