-->
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.  [ 1 post ] 
Author Message
 Post subject: One-to-one mapping using composite keys
PostPosted: Sat Dec 29, 2012 2:11 pm 
Newbie

Joined: Tue Sep 06, 2011 5:17 am
Posts: 1
I have the following configuration in my mapping files for 2 tables.

Table 1:

Code:
<class entity-name="CompPkTest" table="compPkTest" catalog="data" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<composite-id mapped="false" unsaved-value="undefined">
  <key-property name="id1" type="int">
    <column name="id1"/>
  </key-property>
  <key-property name="id2" type="int">
    <column name="id2"/>
  </key-property>
</composite-id>
<property name="details" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
  <column name="Details" length="500"/>
</property>
<one-to-one name="CompPkTestDetail" entity-name="CompPkTestDetail" constrained="false" embed-xml="true"/>


Table 2:

Code:
<class entity-name="CompPkTestDetail" table="compPkTestDetail" catalog="data" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<composite-id mapped="false" unsaved-value="undefined">
  <key-property name="idetail1" type="int">
    <column name="idetail1"/>
  </key-property>
  <key-property name="idetail2" type="int">
    <column name="idetail2"/>
  </key-property>
</composite-id>
<one-to-one name="CompPkTest" entity-name="CompPkTest" constrained="true" embed-xml="true"/>
<property name="someDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
  <column name="someDetail" length="300"/>
</property>
<property name="moreDetail" type="string" unique="false" optimistic-lock="true" lazy="false" generated="never">
  <column name="moreDetail" length="300"/>
</property>


The problem is that when querying table 1, the "details" property is null. If I change the key-property names in CompPkTestDetail to be id1 and id2, (while leaving the column name unchanged), the relationship works as expected, and the query returns a value for "details".

My questions:

Is the above mapping xml the correct way to make this association (with the non-matching field names)?

Is Hibernate correct to impose that the field names must match, or is this a bug?

Please note that I'm using Hibernate 3.6.6 Final and in my web application there are no classes for the entities as Hibernate is in map-mode. The mapping files were originally generated using Hibernate Tools reverse engineering Ant tasks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.