-->
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.  [ 5 posts ] 
Author Message
 Post subject: Neet to use property-ref with one-to-many composite key.
PostPosted: Mon Jun 26, 2006 4:33 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi,

I have a problem wherein I need to use a property-ref tag in one-to-many association.

Following entities are involved:

-------

cm_step
step_id
step_version_d
step_rule_set_id
step_rule_set_version

cm_rule_set
rule_set_id
rule_set_version_id

-------

step_rule_set_id maps to rule_set_id and step_rule_set_version_id maps to rule_set_version_id. Although this is a perfect example of many-to-one association from cm_step to cm_rule_set, I want cm_rule_set object to be deleted when it is unreferenced from cm_step object (orphan deletion). This is not possible with one-to-one or many-to-one association. Hence I have to implement one-to-many from cm_step to cm_rule_set.

<key> element can appear only once in <Set> tag, and <key> element has got 'column' and 'property-ref' support for one column only. Now I cannot use property-ref as I have composite foreign key.

How can I implement this relationship?
Please suggest any other approach if possible.

Thanks in advance!

~ Reshma




Hibernate version:3.0[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 12:08 pm 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
As to the orphan deletion part of your question, it should be easy to implement a separate job that deletes orphans periodically. If you do that then you can map the entities as they really are rather than forcing them into a mapping that might not make sense. Orphan deletion seems counter intuitive to me in this situation.

As to the mapping of the association from cm_step to cm_rule_set, here's how I did it and it seems to work well on my sample program (note the column elements within the key):

Code:
    <class name="CmStep" table="CM_STEP">
        <composite-id>
            <key-property name="stepId" column="STEP_ID" />
            <key-property name="stepVersionId" column="STEP_VERSION_ID" />
        </composite-id>
        <many-to-one name="cmRuleSet" lazy="false">
            <column name="STEP_RULE_SET_ID" />
            <column name="STEP_RULE_SET_VERSION_ID" />
        </many-to-one>
    </class>

    <class name="CmRuleSet" table="CM_RULE_SET">
        <composite-id>
            <key-property name="ruleSetId" column="RULE_SET_ID" />
            <key-property name="ruleSetVersionId" column="RULE_SET_VERSION_ID" />
        </composite-id>
        <set name="cmSteps" inverse="true" lazy="false">
            <key>
                <column name="STEP_RULE_SET_ID"/>
                <column name="STEP_RULE_SET_VERSION_ID" />
            </key>
            <one-to-many class="CmStep" />
        </set>
    </class>

Hope this helps,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 1:42 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hi,

The mapping you specified is already implemented in the application. The orphan deletion problem was encountered later and hence we tried to change the mapping. Since it is not a good practice to manipulate association this way, I guess what you have suggested is right. I'll have to write a job that periodically purges orphan rule sets.

Thanks for your help.

~ Reshma


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 1:45 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There is an alternative. You can map multiple columns as a single property, thus allowing property-ref (which refers to properties, not columns) to refer to them. Check out the ref docs section 5.1.14 to see if this is appropriate for you.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 2:28 am 
Newbie

Joined: Wed May 25, 2005 11:03 am
Posts: 13
Hey tenwit

Thanks for your help. I tried that out. But due to some problem, I am not able to retrieve the association properly. And now we have decided to write a separate job for purging orphan rule set objects keeping relationship many-to-one

Thanks anyways

~ Reshma


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