-->
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: Hi.. mapping a list is not saving the items
PostPosted: Tue Aug 05, 2008 6:58 pm 
Newbie

Joined: Tue Aug 05, 2008 6:05 pm
Posts: 2
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!


Top
 Profile  
 
 Post subject: Re: Hi.. mapping a list is not saving the items
PostPosted: Tue Aug 05, 2008 7:01 pm 
Newbie

Joined: Tue Aug 05, 2008 6:05 pm
Posts: 2
Sorry I have not concluded the problem

The Order is written OK
but hte items are note written on the DB


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.