-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Mapping of Composite-Foreign Keys with Formulas
PostPosted: Sat Nov 22, 2008 3:05 pm 
Newbie

Joined: Sat Nov 22, 2008 2:12 pm
Posts: 2
So I'm working on a project and we're doing a hibernate mapping. To try and outline what I want to do, I'm trying to make a system to archive our data in our system.

What I have is tables A, B, and C.

Table A has:
Primary Key:
A_id
A_version

Table B has:
Primary Key:
B_id
A_id
A_version

Table C has:
Primary Keys:
C_id
A_id
A_version


After being mapped, in Java, these tables come together to form class ABC which contains A as well as sets of B and C.

The way the tables get updated is that if a change occurs in A, a new version in A is inserted into the table with the next version number. If a change occurs in one of the entries in B, then a new version in A is inserted and a new version in B with this same version number. Likewise happens with C. The important part here is that tables B and C might not always have the highest version number as A.

So what I want to do is create a mapping for object ABC which has As data, as well as the sets for B and C. The problem I am having is writing the mapping for the sets to B and C. The problem is that these sets have a composite key and that the value for A_Version is based on a formula.

Can anyone help me write the set mapping? Here's what I've tried so far:



Code:
<set name="b" table="B" cascade="persist,merge" lazy="false">
   <key>
         <column name="A_id"/>
         <column name="A_version"/>
   </key>
      <many-to-many class="b" column="B_id" >
      </many-to-many>
    </set>


However, I'm not sure how I include that requirement about the version potentially not being there. The query I want to execute for the version is:


Code:
         <formula>
         (SELECT max(B.A_Version)
         FROM B
         WHERE B.A_id = A.A_id AND B.A_version <= A.A_version)
         </formula>



Thanks, any help or suggestions would be tremendously appreciated. This has been driving me nuts for about 3 weeks now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2008 11:01 pm 
Newbie

Joined: Sat Nov 22, 2008 2:12 pm
Posts: 2
Does anyone have any ideas what might be the best approach to this or where else I should look for help?


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