-->
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: History Table Mapping Question
PostPosted: Thu Dec 06, 2007 6:46 pm 
Newbie

Joined: Thu Dec 06, 2007 2:07 am
Posts: 3
Not sure how to map these particular types of relationships, and I can't find anything exactly like it after trawling the web - any help would be greatly appreciated. (Please note I've also gotten very little sleep as of late - so I might just be overlooking something)

They both revolve around audit tables where the primary key of each entity is a combination of the object's PKID + a "session" ID that created the records. Whenever the parent object is updated, all children are updated as well (regardless of whether they have changed or not), effectively giving them all the same "session" ID, and adding new records to the audit tables for both parent and child.

Parent
- id
- name
- age
- child_type_one_id
- session_id

ChildTypeOne
- child_type_one_id
- foo
- sessionId

ChildTypeTwo
- parent_id
- bar
- session_id

So when I load a particular version of a Parent from the audit table by (ID + SESSION_ID), how can I map the following two scenarios to have Hibernate load the correct ChildTypeOne and ChildTypeTwo records from those audit tables?

1. load the correct ChildTypeOne record, by using the Parent object's (CHILD_TYPE_ONE_ID + SESSION_ID) columns

2. load the set of ChildTypeTwo records, using the Parent object's (ID + SESSION_ID) columns

FYI - I'm using Hibernate 3.2

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: History Table Mapping Question
PostPosted: Thu Dec 06, 2007 8:16 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
grumpy wrote:
1. load the correct ChildTypeOne record, by using the Parent object's (CHILD_TYPE_ONE_ID + SESSION_ID) columns

2. load the set of ChildTypeTwo records, using the Parent object's (ID + SESSION_ID) columns

FYI - I'm using Hibernate 3.2

Thanks in advance.


1.

Code:
<set name="childTypeOne">
    <key column="child_type_one_id" property-ref="childTypeOneId"/>
    <key column="sessionId" property-ref="sessionId "/>
    <one-to-many class="ChildTypeOne"/>
</set>


2.

Code:
<set name="childTypeTwo">
    <key column="parent_id" property-ref="id"/>
    <key column="session_id" property-ref="sessionId "/>
    <one-to-many class="ChildTypeTwo"/>
</set>



Note childTypeOneId, sessionId and id in property-refs refer to properties in the parent class.


Farzad-


Top
 Profile  
 
 Post subject: Re: History Table Mapping Question
PostPosted: Thu Dec 06, 2007 8:28 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
one another thing you could do for 1 is to use a many-to-one with two nested column tags. However, those two columns should match the primary key of childTypeOne which might not be want you want. Alternatively you might be able to use a join with a nested subselect to rectify this.


Farzad-


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.