-->
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: Mapping problem... need help
PostPosted: Wed Dec 14, 2005 7:23 am 
Newbie

Joined: Tue Dec 13, 2005 11:19 am
Posts: 7
Location: Lisboa, Portugal
I have searched in the book Hibernate in Action, the online documentation and mapping examples, but could not find something which would resemble my problem.

I am maping an existing relational model to use with Hibernate. Its structure was done some years ago and some of it is a real challange to map. This is one of those challanges:

Image

The Class automTrans references two records in AutomStCtxt which has two columns as primary key (composite id).

However, automTrans shares one column (context_code) with the two references.

I have tried two mapping options:

1)
<many-to-one name="automatonStateContext" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="fnl_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
<many-to-one name="initialAutomatonStateCode" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="ini_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>

2)
<many-to-one name="automatonStateContext" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="fnl_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
<property name="initialAutomatonStateCode" type="com.audaxys.fw.dom.usertype.TrimmedStringUserType">
<column name="ini_automst_code" not-null="true" />
</property>

The first option throws a mapping exception because the column context code is used twice. And the second option throws an exception in the insert statement because the foreign key automtrans_fk3 is not met.

Help is much needed, if you can.

Many thanks

_________________
Carlos


Top
 Profile  
 
 Post subject: Apparently I found it.
PostPosted: Thu Dec 15, 2005 12:27 pm 
Newbie

Joined: Tue Dec 13, 2005 11:19 am
Posts: 7
Location: Lisboa, Portugal
using the <formula> like this:

<many-to-one name="initialAutomatonStateCode" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="ini_automst_code" not-null="true" />
<column name="context_code" not-null="true" />
</many-to-one>
<many-to-one name="automatonStateContext" class="com.audaxys.be.autom.dom.AutomatonStateContext">
<column name="fnl_automst_code" not-null="true" />
<formula>context_code</formula>
</many-to-one>

Hope this can be of use to anyone.

_________________
Carlos


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.