Hi! First of all i'm quite new on Hibernate, and I have a little problem and I wish to know what I'm doing wrong.
I have mapped a tipical week entity relationship (say Order - Items) with a list on hibernate:
Here is my Order class:
Code:
//This class is abreviated for this sample
public class Order extends AnotherClassWithId{
protected List<Item> items = new ArrayList<Item>();
public List<ItemBorrador> getItems() {
return items;
}
public void setItems(List<ItemBorrador> items) {
// I have done that because Hibernate used another implementation of
// List, and I need a standar implementation because is serialized by
// GWT, I think this is not my problem because I have the problem
// creating the Order, in wich case the list will naturally not e an Hibernate
// PersistantList, it wil be an arrayList also.
this.items.clear();
this.items.addAll(items);
// this.items = items;
}
}
Here is my Item class:
Code:
//This class is abreviated for this sample
public class Item extends AnotherClassWithId{
protected String data;
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
and here the Order.fbm:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="path.to.Order" table="orders">
<id name="id" column="id">
<generator class="sequence">
<param name="sequence">orders_id_seq</param>
</generator>
</id>
<list name="items" table="items_orders" cascade="all">
<key column="id_order"/>
<list-index column="position"/>
<composite-element class="path.to.Item">
<property name="dato" length="10"/>
</composite-element>
</list>
</class>
</hibernate-mapping>
and here is where I save it (note the code can be better, is not my point, just asking why isn't working
Code:
Transaction tr = HibernateUtil.getSession().beginTransaction();
//Supose the Order already created and received by GWT RPC
//Every thing at this point is correct the Order has the Items I
//wish to be saved
HibernateUtil.getSession().save(order);
HibernateUtil.getSession().flush();
tr.commit();
any clue where can be my problem?
thanks!