Hi.
I have table:
create table ShoppingCart
(
CartID int, not null,
ProductID int not null,
CustomerID int not null,
Quantity int not null,
)
Maybe I am trying to make wrong association...
When I am saving ShoppingCart with Items to DB I have an error like
'Can not insert NULL into ProductID, Quantity'.
Code:
<class name="domainModel.ShoppingCart" table="ShoppingCart">
<id name="ID" column="CartID" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<bag name="Items" table="ShoppingCart" cascade="all">
<key column="CartID"/>
<composite-element class="domainModel.CartItem">
<property name="Quantity" column="Quantity" type="int"/>
<many-to-one name="Product" column="ProductID"/>
</composite-element>
</bag>
<many-to-one name="Customer" column="CustomerID"/>
</class>
Code:
class ShoppingCart {
private int cartId;
private ArrayList items = new ArrayList
private Customer customer;
public ArrayList getItems() {
return items;
}
public void setItems(ArrayList items) {
this.items = items;
}
...
}
class Item {
private int quantity;
private Product product;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
...
}