-->
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: ManyToMany is deleting records from seccond table
PostPosted: Thu Apr 03, 2008 2:19 pm 
Newbie

Joined: Thu Apr 03, 2008 1:56 pm
Posts: 4
hi,

I have a question how to set up @ManyToMany relationship if I have a primary table (User) and second table Tag. user can have multiple tags wich are saved in table user_tag.

In class User I have:
@ManyToMany
Sety<Tag> tags;

I would like to know how to set up that every time user adds tags they are saved in table Tag and User_tag and when it removes a tag it is deleted from table User_tag and it is not removed from Tag table.

Thanks for your help.

Uros


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 3:52 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
Set the cascade to "save-update"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 04, 2008 4:23 am 
Newbie

Joined: Thu Apr 03, 2008 1:56 pm
Posts: 4
Thanks for help. I allready figure it out. It was my mistake. I hava had:

Code:
   @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinTable(name = "Prf_tag", uniqueConstraints = @UniqueConstraint(
         columnNames = {"tag", "user" }),
         joinColumns = { @JoinColumn(name = "user", nullable = false, updatable = false) },
         inverseJoinColumns = { @JoinColumn(name = "tag", nullable = false, updatable = false) })
   @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
   public Set<Tag> getTagsSet() {
      return this.tagsSet;
   }


there should not be: @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)

Thanks, Uros


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.