-->
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: No inserts into my association table with annotations
PostPosted: Thu Jan 14, 2010 5:42 pm 
Newbie

Joined: Thu Jan 13, 2005 9:04 am
Posts: 3
I have a ShoppingCart object that maps to SHOPPING_CART table (primary key SHOPPING_CART_ID)
I have a Purchase object that maps to PURCHASE table (primary key PURCHASE_ID)
I have a table called SHOPPING_CART_PURCHASES (columns SHOPPING_CART_ID and PURCHASE_ID - both columns make a unique key) which is meant to house the associations between shopping carts and purchases.

My ShoppingCart object has a list of Purchase objects.
When I persist ShoppingCart, the Purchase objects that I have added to ShoppingCart purchases are persisted. However no rows are inserted into the association table.

Here is the annotation for ShoppingCart;
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinTable(name="SHOPPING_CART_PURCHASES", joinColumns = {
@JoinColumn(name="SHOPPING_CART_ID", nullable=false, updatable=false) }, inverseJoinColumns = {
@JoinColumn(name="PURCHASE_ID", nullable=false, updatable=false) })
List<Purchase> purchases = this;

Any ideas how to get the associations to be inserted when I persist the ShoppingCart?


Top
 Profile  
 
 Post subject: Re: No inserts into my association table with annotations
PostPosted: Thu Jan 14, 2010 6:21 pm 
Newbie

Joined: Thu Jan 13, 2005 9:04 am
Posts: 3
Found the issue, though I don't think it should be one;

My class extended ArrayList (public class ShoppingCart extends ArrayList...), consequently the purchases property was simply set to this. As;
List<Purchase> purchases = this;

The getter/setter still returned the property purchases.

When I modified my class to NOT subclass ArrayList and then initialized purchases with new ArrayList<Purchase>(), it worked fine.
List<Purchase> purchases = new ArrayList<Purchase>();

Not sure why this is necessary, but at least it works now.


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.