-->
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.  [ 4 posts ] 
Author Message
 Post subject: Question about composite-element
PostPosted: Tue Nov 25, 2003 6:55 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Is it possible to get the ID of a child populated automatically in a non-bidirectional association from parent to child where the children are mapped using composite-element?

e.g.
Code:
    <class name="package.Parent" table="parent">
        <id name="parentID" column="parent_ID" type="int" unsaved-value="0">
            <generator class="identity"/>
        </id>
...
        <map name="children" lazy="true" table="child">
            <key column="parent_ID"/>
            <index column="child_name" type="string"/>
            <composite-element class="package.Child">
                <property name="description" column="child_description"/>
            </composite-element>
        </map>
    </class>

    <class name="package.Child" table="child">
        <composite-id>
            <key-property name="parentID" column="parent_ID" />
            <key-property name="name" column="child_name" type="string"/>
        </composite-id>
        <property name="description" column="child_description" type="string"/>
    </class>


How can I get the parentID property automatically populated on the loaded children? (or can I?)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 10:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You have to map ALL properties of the Child class in the composite-element tag.


Top
 Profile  
 
 Post subject: I already tried that but...
PostPosted: Wed Nov 26, 2003 2:29 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
You have to map ALL properties of the Child class in the composite-element tag


I tried mapping ALL the properties but that causes the multiple column Exception that prevents Hibernate from starting up. I can't (at least not with the version from CVS a week ago) map the key column or index column also to a property because that causes the multiple column problem.
Now here's the weird thing, although I only have the description mapped in the composite-element the child_name also gets populated correctly automatically by Hibernate but the ID does not.

Since I can not duplicate columns I'm not sure how to solve this in the mapping?

It would also appear from my unit test that I do not need the seperate mapping of the Child class, is this correct? (something I was doing before generated an exception if I didn't have the seperate mapping but that seems to have cleared up)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 10, 2005 11:33 pm 
Newbie

Joined: Fri Oct 07, 2005 12:24 am
Posts: 3
Location: Houston, TX
Have you figured this out? I'm brand new to Hibernate but this is a problem I'm just running into. I have a simple relationship mapped with <set> and <composite-element> but I'd like to have the key in the child objects populated... right now it's just coming across as null...


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