-->
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.  [ 3 posts ] 
Author Message
 Post subject: Unidirection Mana-TO-Many - Merge doestn work - NO Cascade
PostPosted: Mon Oct 29, 2007 3:52 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
I have a unidirectional many-to-many relation (with implicit table). I dont want to impact the other side of object (but want to create the mapping), hence I am not using any cascading.
In such scenario, saveUpdate works fine but merge doesnt. And for various reasons, merge is desirable over saveUpdate()

Entity code
Code:
@Entity
@Table(name = "tcr_catalog_tree")
public class TCRCatalogTree implements java.io.Serializable {
@ManyToMany(fetch = FetchType.EAGER)

@JoinTable(name = "tcr_catalog_tree_user", joinColumns = { @JoinColumn(name = "tcr_catalog_tree_id") }, inverseJoinColumns = { @JoinColumn(name = "user_id",insertable = true, updatable=true) })
   private Set<User> assignedUsers = new HashSet<User>(0);

}

_________________
-shailesh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 10:45 am 
Newbie

Joined: Tue Aug 07, 2007 6:18 am
Posts: 3
Hi,

I had a similar problem but I found a workaround (not beautiful but still) like this:

public void setAssignedUsers (Set<User> users) {
if( this.assignedUsers == null) ;
this.assignedUsers = new HashSet<User>();
}
this.assignedUsers .clear();
this.assignedUsers .addAll(children);
}

My problem is fully described at:"Collection update (merge) problem"

Please, let me know if that fixed your problem.

Regards
/ daiv


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 30, 2007 12:10 pm 
Beginner
Beginner

Joined: Fri Jun 29, 2007 2:19 pm
Posts: 26
Location: Fremont, CA
No, it didn't, Here is my work around. I created a specific method to update the Many-To-Many collection.
Code:
- Retrieve the object from db
- copied the collection (much like you suggested)
- Call getHibernateTemplate().[b]saveOrUpdate[/b](objectTobeSave);


Crux is - SaveOrUpdate is will always to work. In may not be possible in all cases to explicitly save the collection. It worked in our case.

-Shailesh

_________________
-shailesh


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.