-->
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: Bidirectional ManyToMany
PostPosted: Sat Jul 28, 2007 10:41 am 
Newbie

Joined: Thu Jul 26, 2007 5:08 pm
Posts: 6
This might sound simple, but it is not working as it was supposed to be... I think I might be missing something...

I have the following code with ManyToMany but when I insert a Product in the Basket's product list it does not persist and does not update the list from the Product.


Code:
@Entity
@Table(name = "PRODUCT")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Product implements java.io.Serializable
{
   @ManyToMany(cascade=CascadeType.ALL)
   @JoinTable(name="BASKET_PRODUCT",
   joinColumns={@JoinColumn(name="PRODUCT_ID", nullable=false)},
          inverseJoinColumns={@JoinColumn(name="BASKET_ID", nullable=false)})
   List<Basket> baskets;
}


Code:
@Entity
@Table(name = "BASKET")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Basket implements java.io.Serializable
{
   @ManyToMany(mappedBy="baskets", cascade=CascadeType.ALL)
   List<Product> products;

   public void addProduct(Product product)
   {
      this.products.add(product);
   }
}


Top
 Profile  
 
 Post subject: Oops
PostPosted: Sat Jul 28, 2007 4:04 pm 
Newbie

Joined: Thu Jul 26, 2007 5:08 pm
Posts: 6
My mistake...

Taken from the manual:

"If the association is bidirectional, one side has to be the owner and one side has to be the inverse end (ie. it will be ignored when updating the relationship values in the association table)"


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.