-->
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.  [ 1 post ] 
Author Message
 Post subject: Parent - Child - Grandchild Relationship
PostPosted: Tue May 10, 2005 4:15 pm 
Newbie

Joined: Tue Apr 19, 2005 11:24 am
Posts: 8
Hibernate version: 3.0.3

I have been working on this problem for a while, and for some reason I cannot seem to get it properly working properly. What I have been trying to do is have a Parent - Child - Grandchild relationship where everything is cascaded by "all-delete-orphan" up to the "Parent". That way I should only have to call the save() on the Parent (at least that's how I interpreted the documentation as well as the book Hibernate in Action).

I have the following relationship:

TransactionLog----(1 to many)----TransactionGroup----(1 to many)----Transaction

Mapping documents:
TransactionLog.hbm.xml:
Code:
<hibernate-mapping>
    <class name="TransactionLog" lazy="false">
        <id name="id" column="TRANSACTION_LOG_ID">
            <generator class="native"/>
        </id>
   
        <set name="transactionGroups" cascade="all-delete-orphan" inverse="true" lazy="true">
            <key column="LOG_PARENT_ID"/>
            <one-to-many class="TransactionGroup"/>
        </set>
    </class>
</hibernate-mapping>


TransactionGroup.hbm.xml:
Code:
<hibernate-mapping>
    <class name="TransactionGroup" lazy="false">
        <id name="id" column="TRANSACTION_GROUP_ID">
            <generator class="native"/>
        </id>
   
        <many-to-one name="parent" column="LOG_PARENT_ID" not-null="true"/>

        <set name="transactions" cascade="all-delete-orphan" inverse="true" lazy="true">
            <key column="PARENT_ID"/>
            <one-to-many class="Transaction"/>
        </set>
    </class>
</hibernate-mapping>


Transaction.hbm.xml:
Code:
<hibernate-mapping>
    <class name="Transaction" lazy="false">
        <id name="id" column="TRANSACTION_ID">
            <generator class="native"/>
        </id>
   
        <many-to-one name="parent" column="PARENT_ID" not-null="true"/>
    </class>
</hibernate-mapping>


Name and version of the database you are using: PostgresQL 8.0

When I am adding a Transaction to a TransactionGroup, the code is something of the following: (Assuming that the code is located in the TransactionGroup class and getTransactions() returns a lazily-initialized Set)

Code:
void addTransaction(Transaction value) {
    getTransactions().add(value);
    value.setParent(this);
}


The code is similar for the TransactionLog and the TransactionGroup.

The error that I have encountered while trying all of this is that I get: ERROR: insert or update on table "transaction" violates foreign key constraint ...

I am now stuck, and just don't really know how to go about fixing this. Any help would be appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.