-->
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: help to identify mapping
PostPosted: Tue Jul 05, 2011 3:46 am 
Newbie

Joined: Tue Jul 05, 2011 1:30 am
Posts: 1
Hi,
this is my first post in this forum..I am developing a web app that has an Invoice,CartItem,Customer classes..I need to identify the kind of mapping I need to create.

A user creates cartitems and adds them to ShoppingCart .
An Invoice has a Customer and a Set of CartItem objects.I believe cartitem is not dependent upon the invoice's lifetime.So, when an invoice is deleted,the cartitems should not be deleted.

I tried to create the Invoice.hbm.xml and used <set> to associate cartItems to Invoice and decided to not to mention cascade option so that deletion of Invoice does not affect cartitems.

I would like some advice/opinion regarding this..Is this the right way of mapping the associations?
I have copied relevant portions of the code below..Please tell me if this is the correct way.

thanks,
mark

Invoice.java
==========
public class Invoice {
private Customer customer;
private Set<CartItem> cartItems;
private Date invoiceDate;
private int invoiceNumber;
private boolean isProcessed;
public Invoice() {
super();
isProcessed = false;
cartItems = new HashSet<CartItem>();
}
...
}
CartItem.java
========
public class CartItem {
private Product product;
private int quantity;
...
}

Invoice.hbm.xml
==========
...
<class name="Invoice" table="INVOICE">
<id name="invoice_id" column="INVOICE_ID" type="long">
<generator class="native"/>
</id>
<property name="invoiceDate" type="date" column="INVOICE_DATE" />
<property name="invoiceNumber" type="int" column="INVOICE_NUMBER" unique="true"/>
<property name="isProcessed" type="boolean" column="IS_PROCESSED" />

<many-to-one name="customer" class="Customer" column="CUSTOMER_ID" lazy="false" />

<!--when an invoice is deleted the cart items should not be deleted -->
<set name="cartItems" table="CARTITEM" lazy="false" >
<key column="INVOICE_ID" />
<one-to-many class="CartItem" />
</set>
</class>
...


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.