>> At this point hibernate first tries to save the child
record <<

No, cascades to collections happen *after*. ie. the child
will be saved after the parent.

Anyway, The sequence of steps *should* be

>1) I create an new parent class
>2) I create a new child class
>3) I add the child record to the parent class's set
new) set the child's parent property to point to the parent
>4) I save the parent record


And, secondly, you *must* map the set with readonly="true".

There are lots of examples of this stuff in the .test
package.




                                                                                       
                                               
                    "Matt Dowell"                                                      
                                               
                    <[EMAIL PROTECTED]>                To:     <[EMAIL PROTECTED]>     
                      
                    Sent by:                                cc:                        
                                               
                    [EMAIL PROTECTED]       Subject:     [Hibernate] More - Saving 
Collections.                       
                    eforge.net                                                         
                                               
                                                                                       
                                               
                                                                                       
                                               
                    31/01/03 01:58 AM                                                  
                                               
                                                                                       
                                               
                                                                                       
                                               




I have made progress saving my collections (thanks to Gavin), and I am
down to my last bug, I think. Here is what is happening:

1) I create an new parent class
2) I create a new child class
3) I add the child record to the parent class's set
4) I save the parent record

At this point hibernate first tries to save the child record, but it
does not yet get the sequence for the parent record so it tries to
insert NULL into the key column for the parent record and the DB is
throwing a SQL error. Any ideas?

Here are my mapping files:


  PARENT
------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd";>
<hibernate-mapping>

    <class name="com.notiva.entity.submatch.SubMatch" table="SUB_MATCH">
        <id name="id" type="java.lang.Long" unsaved-value="null">
            <column name="SUB_MATCH_ID" />
            <generator class="sequence">
                <param>SEQ_SUB_MATCH_ID</param>
            </generator>
        </id>

        <property column="MATCH_ID" length="10" name="matchId"
not-null="true" type="java.lang.Long"/>
        <property column="MATCH_LEVEL_ID" length="10"
name="matchLevelId" not-null="true" type="java.lang.Long"/>
        <property column="REASON_CODE_ID" length="10"
name="reasonCodeId" type="java.lang.Long"/>
        <property column="VARIANCE_AMT" length="18" name="varianceAmt"
not-null="true" type="java.lang.Double"/>
        <property column="DISPUTE_AMT" length="18" name="disputeAmt"
type="java.lang.Double"/>
        <property column="ADJUSTMENT_DESC_TXT" length="100"
name="adjustmentDescTxt" type="java.lang.String"/>

        <set role="invoices" table="SUB_MATCH_INVOICE" readonly="false"
cascade="all">
            <key column="SUB_MATCH_ID" />
            <one-to-many
class="com.notiva.entity.submatch.SubMatchInvoice"/>
        </set>

    </class>
</hibernate-mapping>


  CHILD
---------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd";>
<hibernate-mapping>
    <class name="com.notiva.entity.submatch.SubMatchInvoice"
table="SUB_MATCH_INVOICE">

        <id  name="id" type="java.lang.Long" unsaved-value="null">
            <column name="SUB_MATCH_INVOICE_ID"/>
            <generator class="sequence">
                <param>SEQ_INVOICE_ID</param>
            </generator>
        </id>

        <property column="INVOICE_ID" length="10" name="invoiceId"
not-null="true" type="java.lang.Long"/>
        <property column="CREATE_TS" length="11" name="createTs"
not-null="true" type="timestamp"/>
        <property column="CREATE_USER_TXT" length="40"
name="createUserTxt" not-null="true" type="java.lang.String"/>

        <many-to-one name="subMatchId" column="SUB_MATCH_ID"
class="com.notiva.entity.submatch.SubMatch"
            cascade="all" unique="true" not-null="true"
outer-join="true" />

    </class>
</hibernate-mapping>

Thanks,

Matt Dowell
Notiva Corp


-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel




**********************************************************************
Any personal or sensitive information contained in this email and
attachments must be handled in accordance with the Victorian Information
Privacy Act 2000, the Health Records Act 2001 or the Privacy Act 1988
(Commonwealth), as applicable.

This email, including all attachments, is confidential.  If you are not the
intended recipient, you must not disclose, distribute, copy or use the
information contained in this email or attachments.  Any confidentiality or
privilege is not waived or lost because this email has been sent to you in
error.  If you have received it in error, please let us know by reply
email, delete it from your system and destroy any copies.
**********************************************************************





-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to