-->
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.  [ 6 posts ] 
Author Message
 Post subject: Confusion on the key-many-to-one syntax
PostPosted: Wed Jun 21, 2006 4:03 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
[b]Hibernate version:[/b] 3.x

[b]Mapping documents:[/b]

<class name="us.tx.state.oag.WfPersonnelAction.HbmWfPaPersonnelActionTable"
table="info_wf_action">

<composite-id>
<!-- <key-property name="BatchId" column="batch_id" type="big_decimal"/> -->
<key-many-to-one name="BatchId" column="batch_id"/>
<key-property name="ActionId" column="action_id" type="big_decimal"/>
</composite-id>

<!--
<many-to-one name="BatchId" column="batch_id" cascade="all" not-null="true" update="false" insert="false"
class="us.tx.state.oag.WfPersonnelAction.HbmWfPaActionBatchTable"/>
-->
<many-to-one name="ActionTypeId" column="action_type_id" cascade="all" not-null="true" update="false" insert="false"
class="us.tx.state.oag.WfPersonnelAction.HbmWfPaCodeActionTypeTable"/>

<property name="CreatedWho" column="cr_who" type="string" update="true" insert="true"/>
<property name="CreatedWhen" column="cr_when" type="timestamp" update="true" insert="true"/>
<property name="UpdatedWho" column="up_who" type="string" update="true" insert="true"/>
<property name="UpdatedWhen" column="up_when" type="timestamp" update="true" insert="true"/>

</class>


Note the items that are commented out as opposed to active. The Active ones throw an error:

org.hibernate.MappingException: An association from the table info_wf_action refers to an unmapped class:
java.math.BigDecimal

Odd, since that's an internal data type.

We use natural keys almost exclusively. Just trying to figure out the best way to represent the relationships back to the parent tables. In this example, batch_id is the child here.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:34 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Code:
<composite-id>
<key-property name="BatchId" column="batch_id"/>
<key-property name="ActionId" column="action_id" type="big_decimal"/>
</composite-id>


did you map BatchId as key-many-to-one instead of key-property intentionally or was that a mistake

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 8:58 am 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
That is my confusion. In this case, the info_wf_action table is a child to the info_wf_action_batch table; many-to-one in that same direction.

I'm sure there are multiple ways of doing this, but I'm trying to understand the key-many-to-one - what do I gain by using this syntax? (Beyond documentation in the xml file?) Is it better than the key-property and a follow up many-to-one?

Or is it just 6-of one and half-dozen of another?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 9:32 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
You can have your mappings in the following way.

Code:
<class name="us.tx.state.oag.WfPersonnelAction.HbmWfPaPersonnelActionTable" table="info_wf_action">

   <composite-id>
      <key-many-to-one name="BatchId" column="batch_id" class="YourJoinTableMappingClass"/>
      <key-property name="ActionId" column="action_id" type="big_decimal"/>
   </composite-id>

   
   <many-to-one name="ActionTypeId"
                column="action_type_id"
                cascade="all-delete-orphan"
                class="us.tx.state.oag.WfPersonnelAction.HbmWfPaCodeActionTypeTable"/>


   <property name="CreatedWho" column="cr_who" type="string" update="true" insert="true"/>
   <property name="CreatedWhen" column="cr_when" type="timestamp" update="true" insert="true"/>
   <property name="UpdatedWho" column="up_who" type="string" update="true" insert="true"/>
   <property name="UpdatedWhen" column="up_when" type="timestamp" update="true" insert="true"/>

</class>


Code:
<class name="us.tx.state.oag.WfPersonnelAction.HbmWfPaPersonnelActionTable" table="info_wf_action">

   <composite-id>
      <key-property name="BatchId" column="batch_id" type="big_decimal"/>
      <key-property name="ActionId" column="action_id" type="big_decimal"/>
   </composite-id>

   <many-to-one name="BatchIdObject"
                column="batch_id"
                cascade="all"
                update="false"
                insert="false"
                class="us.tx.state.oag.WfPersonnelAction.HbmWfPaActionBatchTable"/>

   <many-to-one name="ActionTypeId"
                column="action_type_id"
                cascade="all"
                update="false"
                insert="false"
                class="us.tx.state.oag.WfPersonnelAction.HbmWfPaCodeActionTypeTable"/>

   <property name="CreatedWho" column="cr_who" type="string" update="true" insert="true"/>
   <property name="CreatedWhen" column="cr_when" type="timestamp" update="true" insert="true"/>
   <property name="UpdatedWho" column="up_who" type="string" update="true" insert="true"/>
   <property name="UpdatedWhen" column="up_when" type="timestamp" update="true" insert="true"/>

</class>


With the second mapping I removed key-many-to-one in composite-id and replaced it with key-property element. Also I have many-to-one element with insert="false" and update="false"

You can use either of <key-property> and <key-many-to-one> in your mappings. When you specify <key-many-to-one> you also need to specify the mapping class to which there is a relation defined. But if you want to get rid of <key-many-to-one> and use only <key-property> then the relation between the tables can be defined using <many-to-one> element using insert="false" and update="false" attributes. See this link for more information. http://www.hibernate.org/117.html#A34


Last edited by bkmr_77 on Thu Jun 22, 2006 12:25 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 9:33 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
duplicate post, hence contents deleted


Top
 Profile  
 
 Post subject: name="x" and other confusion
PostPosted: Thu Jun 22, 2006 4:02 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
The following seems to compile:

<class name="us.tx.state.oag.WfPersonnelAction.hbm.HbmWfPaSignaturesTable"
table="info_wf_action_signatures">

<composite-id>
<key-property name="BatchId" column="batch_id" type="big_decimal"/>
<key-property name="ActionId" column="action_id" type="big_decimal"/>
<key-property name="SignatureId" column="signature_id" type="big_decimal"/>
<key-property name="SignatureDate" column="signature_date" type="timestamp"/>
</composite-id>

<many-to-one name="BatchId" column="batch_id" cascade="all" not-null="true" update="false" insert="false"
class="us.tx.state.oag.WfPersonnelAction.hbm.HbmWfPaActionBatchTable"/>

<many-to-one name="ActionId" not-null="true" update="false" insert="false"
class="us.tx.state.oag.WfPersonnelAction.hbm.HbmWfPaPersonnelActionTable">
<column name="BatchId"/>
<column name="ActionId"/>
</many-to-one>

<many-to-one name="SignatureId" column="signature_id" cascade="all" not-null="true" update="false" insert="false"
class="us.tx.state.oag.WfPersonnelAction.hbm.HbmWfPaCodeActionSignaturesTable"/>

<!-- field definitions follow -->

But what I don't understand is why there is a name="" on the many-to-one; indeed w/o it the mapping is "invalid". As shown in the <composite-id> section, the primary key of my table is a quaternary one. I finally found the syntax for the many-to-one that can relate this class to the parent table with a primary key that is comprised of the first two fields. The third field of this table's PK is a single field FK to the signatures table. Ok. All's well.

Why do I need a name on the many-to-one and why does it have to be named after an existing field? "ID" doesn't work (as in composite-id) and missing isn't allowed.

This doesn't make sense to me.


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