-->
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.  [ 3 posts ] 
Author Message
 Post subject: Denormalize grandparent's id in grandchildren
PostPosted: Tue Jan 02, 2007 8:26 pm 
Newbie

Joined: Mon Jun 12, 2006 7:25 pm
Posts: 7
Hi,

Can someone tell me if it's possible to pull grandparent's generated id and have it persisted in the grandchild. Here is the scenario:

GrandParent->Parent->Child

Each class declares a generated id as primary key:
<class name="GrandParent">
<id name="grandParentId" column="GRANDPARENT_ID">
<generator class=.../>
</id>
...
</class>

<class name="Parent">
<id name="parentId" column="PARENT_ID">
<generator class=.../>
</id>
...
</class>

<class name="Child">
<id name="childId" column="CHILD_ID">
<generator class=.../>
</id>
...
</class>


I already have a bi-directional collection mapping from Parent to Child:

<bag name="children" lazy="false" inverse="true">
<key column="PARENT_ID"/>
<one-to-many class="Child" />
</bag>

And the child has the many-to-one mapping:

<many-to-one name="customer" column="PARENT_ID" class="Parent" not-null="true"/>

I'd like the GRANDPARENT_ID column added to the Child and persisted as part of the collection mapping from Parent to Child. Is this possible?

Thanks,
Ali


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 5:12 am 
Regular
Regular

Joined: Thu Aug 17, 2006 4:50 am
Posts: 55
Location: Mallorca
Maybe it could be useful to use the formula attribute for the property element :

from the documentation :

Code:
<property
        name="propertyName"                                          (1)
        column="column_name"                                         (2)
        type="typename"                                              (3)
        update="true|false"                                          (4)
        insert="true|false"                                          (4)
        [b]formula="arbitrary SQL expression" [/b]                          (5)
        access="field|property|ClassName"                            (6)
        lazy="true|false"                                            (7)
        unique="true|false"                                          (8)
        not-null="true|false"                                        (9)
        optimistic-lock="true|false"                                 (10)
        generated="never|insert|always"                              (11)
        node="element-name|@attribute-name|element/@attribute|."
        index="index_name"
        unique_key="unique_key_id"
        length="L"
        precision="P"
        scale="S"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 5:29 am 
Beginner
Beginner

Joined: Tue Aug 29, 2006 8:13 pm
Posts: 32
Location: Spain (GU)
I advice to see the Hibernate in Action Book (Manning), in the page 103 is the solution for this cases. You should use a joined-subclass tag with a key tag. It is really complex for explain in a forum, but I hope to be helping you.

You could read the reference documentation in the joined-subclass topic, and inheritance class mapping.

Regards.

_________________
Please don't forget the credit system.


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