Hi,
I'm having two classes Invoice and ItemLines.
The invoice class is:
Code:
public class Invoice extends BaseObject implements Serializable {
   private Long id;
   private Integer invoiceNumber;
   private Customer customer;
   private Date date;
   private List itemLines = new ArrayList();
   private double totalPrice;
The  ItemLines class is:Code:
public class ItemLine extends BaseObject implements Serializable {
   private Long id;
   private Item item;
   private double quantity;
   private double unitPrice;
   private double totalPrice;
   private Invoice invoice;
The .hbm file for the invoice class is:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
    <class
        name="com._4s_.invoice.model.Invoice"
        table="invoice"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >
        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
              <!--  
                  To add non XDoclet generator parameters, create a file named 
                  hibernate-generator-params-Invoice.xml 
                  containing the additional parameters and place it in your merge dir. 
              --> 
            </generator>
        </id>
        <many-to-one
            name="customer"
            class="com._4s_.invoice.model.Customer"
            cascade="none"
            outer-join="false"
            update="true"
            insert="true"
            access="property"
            column="customer"
        />
        <property
            name="date"
            type="java.util.Date"
            update="true"
            insert="true"
            access="property"
            column="invoicedate"
        />
        <property
            name="invoiceNumber"
            type="java.lang.Integer"
            update="true"
            insert="true"
            access="property"
            column="invoicenumber"
            unique="true"
        />
        <list
            name="itemLines"
            table="itemline"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
        >
              <key
                  column="invoice"
              >
              </key>
              <index
                  column="position"
              />
              <one-to-many
                  class="com._4s_.invoice.model.ItemLine"
              />
        </list>
        <property
            name="totalPrice"
            type="double"
            update="true"
            insert="true"
            access="property"
            column="totalprice"
        />
        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-Invoice.xml
            containing the additional properties and place it in your merge dir.
        -->
    </class>
</hibernate-mapping>
The .hbm file for the ItemLine class is:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN" 
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
    <class
        name="com._4s_.invoice.model.ItemLine"
        table="itemline"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >
        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
              <!--  
                  To add non XDoclet generator parameters, create a file named 
                  hibernate-generator-params-ItemLine.xml 
                  containing the additional parameters and place it in your merge dir. 
              --> 
            </generator>
        </id>
        <many-to-one
            name="invoice"
            class="com._4s_.invoice.model.Invoice"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            access="property"
            column="invoice"
        />
        <many-to-one
            name="item"
            class="com._4s_.invoice.model.Item"
            cascade="none"
            outer-join="true"
            update="true"
            insert="true"
            access="property"
            column="item"
        />
        <property
            name="quantity"
            type="double"
            update="true"
            insert="true"
            access="property"
            column="quantity"
        />
        <property
            name="unitPrice"
            type="double"
            update="true"
            insert="true"
            access="property"
            column="unitprice"
        />
        <property
            name="totalPrice"
            type="double"
            update="true"
            insert="true"
            access="property"
            column="totalprice"
        />
        <property
            name="position"
            type="int"
            update="true"
            insert="true"
            access="property"
            column="position"
        />
        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-ItemLine.xml
            containing the additional properties and place it in your merge dir.
        -->
    </class>
</hibernate-mapping>
- When I create a new invoice instance and add a new itemLine to this invoice and then save the invoice , it works well.
- When I create a new invoice instance and add a new itemline to this invoice then I remove this itemline then save , it works well too.
-
But the problem is that: when I get an invoice instance that was previously saved and and add a new item line to this invoice then remove this itemLine  and then save the invoice I get the following error:
object references an unsaved transient instance - save the transient instance before flushing: com._4s_.invoice.model.ItemLine
What I was expecting is that the invoice will be saved and the itemLine which I added and then removed will not be save to the invoice and will cause no problem.
I don't know why does this error occurs and how could I solve it.
Could anyone help me in that.
Thanks in advance.