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!
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.
MERGE Do I really want to update a country when an address changes? I
can't find a system that would do that.
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 :)
On Mar 4, 2009, at 14:38, Dan Allen wrote:
On Wed, Mar 4, 2009 at 2:17 PM, Emmanuel Bernard
<emmanuel(a)hibernate.org
> wrote:
Then add @*to*(cascade=CascadeType.PERSIST), it will take you 2 mins
to do what you really like and you will know you do it.
It doesn't take two minutes when you have 80 entities. Most apps
have large databases. Rarely do you see simple schemas like we have
in the examples. When you generate your entities again and have to
start all over. I think this is a good default to have, as well as
DELETE and maybe REFRESH. Daniel can speak better to what he is
seeing out in the field.
NONE is a crappy default.
-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.