-->
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.  [ 1 post ] 
Author Message
 Post subject: @ManyToMany and @JoinTable delete
PostPosted: Wed Aug 10, 2011 10:28 am 
Newbie

Joined: Wed Aug 10, 2011 9:52 am
Posts: 2
Hi
I have an object call user which has a list of attribute as its property:

@Entity(name = "User")
@Table(name = "tz_user")
Code:
public class User{
   private Long userId;
   private Set<Attribute> attributes;

  @ManyToMany(fetch = FetchType.LAZY, cascade = {javax.persistence.CascadeType.DETACH})
   @Cascade({CascadeType.DELETE_ORPHAN, CascadeType.SAVE_UPDATE})
   @JoinTable(name = "tz_userattributes",
         joinColumns = @JoinColumn(name = "userId"),
         inverseJoinColumns = @JoinColumn(name = "attributeId"))
  public Set<Attribute> getAttributes() {
      return attributes;
  }
}


the attribute object:

Code:
@Entity(name = "Attribute")
@Table(name = "tz_attribute")
public class Attribute extends {
   private Long attributeId;
   private String value;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public Long getAttributeId() {
      return attributeId;
   }

   public void setAttributeId(Long attributeId) {
      this.attributeId = attributeId;
   }

      this.type = type;
   }

   public String getValue() {
      return value;
   }

   public void setValue(String value) {
      this.value = value;
   }

}




Whenever I delete with session.delete an item from the list of attributes....only the row in the "tz_userattributes"
joined table is removed.How can I remove the attribute from the "tz_attribute" table?

Thanks
Lilachha


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

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.