-->
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.  [ 8 posts ] 
Author Message
 Post subject: Many-to-one of a parent class not loading in Beta 6
PostPosted: Wed Nov 12, 2003 6:24 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
When we load the child with a many-to-one and ther is a <many-to-one on the parent, like this:

INVOICE_LINE -> INVOICE -> SELLER_PARTNERSHIP

The "SellerPartnership" is not loading and it is causing us problems. We are on Beta 6.

Any ideas?

Here is a quote from the user:

"when I try to load invoice alone, It is loading sellerPartnershipImpl successfully. But when try to invoiceLine, Invoice is loading without sellerPartnershipImpl."


Invoice.hbm.xml

Code:
<hibernate-mapping>
    <class name="com.notiva.cbo.buyer.data.invoice.InvoiceImpl" table="INVOICE">
        <id column="INVOICE_ID" name="id" type="java.lang.Long" unsaved-value="null">
            <generator class="com.notiva.util.hibernate.SequenceIntervalGenerator">
                <param name="sequence">SEQ_INVOICE_ID</param>
                <param name="interval">1</param>
            </generator>
        </id>
        <many-to-one column="SELLER_PARTNERSHIP_ID" name="partnership" not-null="true" class="com.notiva.cbo.buyer.data.partnership.SellerPartnershipImpl"/>
        <set name="invoiceLines" cascade="all" lazy="true">
            <key column="INVOICE_ID"/>
            <one-to-many class="com.notiva.cbo.buyer.data.invoice.InvoiceLineImpl"/>
        </set>
   </class>
</hibernate-mapping>


InvoiceLine.hbm.xml

Code:
<hibernate-mapping>
    <class name="com.notiva.cbo.buyer.data.invoice.InvoiceLineImpl" table="INVOICE_LINE">
        <id column="INVOICE_LINE_ID" name="id" type="java.lang.Long" unsaved-value="null">
            <generator class="com.notiva.util.hibernate.SequenceIntervalGenerator">
                <param name="sequence">SEQ_INVOICE_LINE_ID</param>
                <param name="interval">1</param>
            </generator>
        </id>
        <many-to-one column="INVOICE_ID" name="invoice" not-null="true" class="com.notiva.cbo.buyer.data.invoice.InvoiceImpl"/>
</class>
</hibernate-mapping>


SellerPartnership.hbm.xml


Code:
<hibernate-mapping>

<class name="com.notiva.cbo.buyer.data.partnership.SellerPartnershipImpl" table="SELLER_PARTNERSHIP_SETUP">

        <id column="SELLER_PARTNERSHIP_ID" name="id" type="java.lang.Long" unsaved-value="null">
            <generator class="com.notiva.util.hibernate.SequenceIntervalGenerator">
                <param name="sequence">SEQ_SELLER_PARTNERSHIP_ID</param>
                <param name="interval">1</param>
            </generator>
        </id>

        <many-to-one name="buyer" cascade="all" class="com.notiva.cbo.buyer.data.partnership.BuyerImpl"
         column="BUYER_ID" not-null="true"/>

        <property column="SELLER_COLLAB_UID_TXT" name="sellerUid" type="java.lang.String"/>
        <!-- property column="SETTING_SCOPE_ID" name="shortName" type="java.lang.Integer"/ -->

        <!-- Abstract Company -->
        <property column="SHORT_NAME_TXT" name="shortName" type="java.lang.String"/>
        <property column="LONG_NAME_TXT" name="longName" type="java.lang.String"/>
        <property column="COMPANY_CODE_TXT" name="companyCode" type="java.lang.String"/>

        <!-- Auditable -->
        <property column="CREATE_TS" name="createTs" type="timestamp"/>
        <property column="CREATE_USER_TXT" name="createUserTxt" type="java.lang.String"/>
        <property column="UPDATE_TS" name="updateTs" type="timestamp"/>
        <property column="UPDATE_USER_TXT" name="updateUserTxt" type="java.lang.String"/>

        <!-- EFECTIVITY -->
        <property column="EFF_START_DT" name="effectiveStartDate" type="timestamp"/>
        <property column="EFF_END_DT" name="effectiveEndDate" type="timestamp"/>

    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 11:03 am 
Beginner
Beginner

Joined: Wed Nov 26, 2003 11:53 am
Posts: 26
Location: Netherlands
Matt,

I have the same problem: did you find a solution? I find that everything works fine as long as I load the parent object and then navigate to the child, but when I directly query the child (from [classname] as obj where obj.id = ?) and later try to save or update it, I get the error that the parent relationship is null.

net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: nl.sogeti.piloot.server.model.Message.book
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1211)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:873)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:740)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1334)

I checked if the book would be null by implementing Validatable. I get this.

net.sf.hibernate.ValidationFailure: Parent (Book) should not be null on Message with persistent id 4294998791
at nl.sogeti.piloot.server.model.Message.validate(Message.java:331)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:831)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:740)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1334)

Did you have any luck with this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 11:50 am 
Beginner
Beginner

Joined: Wed Nov 26, 2003 11:53 am
Posts: 26
Location: Netherlands
Trying a lot of different solutions: but nothing. Is because I have to work on Sunday, or is there no way that the child will load its parent in a bidirectional parent/child relationship? Sigh...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:16 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
I finally tracked down how we fixed this, this is what the user is reporting fixed it anyways. Change your child mapping to this:

<hibernate-mapping default-cascade="save-update">

..and aparently that made the issue go away. Go figure.

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:19 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 11:53 am
Posts: 26
Location: Netherlands
You add the cascade to the mapping file of the child?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:24 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 11:53 am
Posts: 26
Location: Netherlands
Sorry, quick reply: the XML tag looks like something that should be in the hibernate.cfg.xml. Should it go there, or in the child hbm.xml mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:37 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
It's the new top element for the child, so it is the new mapping for the INVOICE_LINE mapping.

<hibernate-mapping default-cascade="save-update">
<class name="com.acme.InvoiceLineImpl" table="INVOICE_LINE">
....
</class>
</hibernate-mapping>

SergeBeaumont wrote:
Sorry, quick reply: the XML tag looks like something that should be in the hibernate.cfg.xml. Should it go there, or in the child hbm.xml mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 12:45 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 11:53 am
Posts: 26
Location: Netherlands
aha and darn. I use XDoclet to generate the mapping files, and there's no support for that attribute in 1.2... If only I knew anything useful about XDoclet, I could maybe do somthing about it... ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.