-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Cascade links only of a @ManyToMany unidirectional relation
PostPosted: Fri Jul 06, 2007 6:09 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Is it possible to cascade only the links of a ManyToMany relation and not the related objects?

For example:

I have 2 classes: Person and Dog, which have a many to many relation.
Both are CRUD'ed independently.

Person has a undirectional @ManyToMany relation to dogs:
class Person
{
...

@ManyToMany(
// cascade = {CascadeType.PERSIST, CascadeType.MERGE}
)
@CollectionId(...)
@JoinTable(
name="Person_Dog"
)
public List<Dog> getDogs()...
}

I add 2 dogs A, B to a person C without dogs.

If I don't cascade, the person C doesn't have any dogs.
If I do cascade, changes to A and B are also saved.
What I really want is that the table Person is affected, as well as the table Peron_Dog, but not the table Dog.

Is this possible?
Thanks for any help.

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 6:32 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Removing @CollectionId and not only using an update of Person (instead of directly inserting a Person with linked dogs) seems to do what I want.
But why?

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.