-->
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: constant value in many-to-one but wrong 'primary key'
PostPosted: Wed Oct 20, 2004 6:27 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
Hibernate version: 2.1.6

Mapping documents:
only parts showing the relevant things ... i hope i have correctly pasted them ...

that works, but with the wrong primary key:
Part of Mapping for Class A:
Code:
<class
  name="ClassA"
  table="A"
  mutable="false">

  ...

  <many-to-one
    name="classB"
    class="ClassB"
    insert="false"
    update="false"
    cascade="none"
    property-ref="uniqueKey">
     <column name="numberA"/>
     <column name="276"/>
  </many-to-one>
</class>


Part of Mapping for Class B
Code:
<class
    name="ClassB"
    table="B"
    mutable="false"
>
  <id ... (a field - just to have an pk declared in mapping-file) />

  <component
    name="uniqueKey"
    class="BID">

    <property
      name="numberA"
        column="numberA"
        type="integer"
        length="3"/>

    <property
      name="cuntryCode"
      column="cuntryCode"
      type="integer"
      length="3"/>       
</component>
 
  ...

</class>


that doesn't work, but the pk-definition is correct:
Part of Mapping for Class A
Code:
<just the same ...>



Part of Mapping for Class B
Code:
<class
    name="ClassB"
    table="B"
    mutable="false"
>
  <composite-id
    name="uniqueKey"
    class="BID">

    <key-property
      name="numberA"
        column="numberA"
        type="integer"
        length="3"/>

    <key-property
      name="cuntryCode"
      column="cuntryCode"
      type="integer"
      length="3"/>       
</component>
 
  ...

</class>


Question:
Hi,

i've got only a little step to success :), but this step it seems for me, i can't go ...

The Situation:
I have to use a legacy db which i'm not allowed to change (even i really really would like to do :) ).
I have a Class A and a Class B.
Class A has a "many-to-one" relationship to Class B.

Tables:
Code:
-----
A
password VARCHAR (pk)
numberA integer  (one part of the foreign key)
-----
B
numberA integer (pk)
cuntryCode integer (pk)
  (some more data)
-----


My problem was, that one information in A is missing to uniquely identify B -> the countryCode.
Well, the countryCode is fix for my application, so i can use it as a constant-value.

Gavin gave the intial hint in this thread.

Creating a "component" containg the two primary-key values of B works perfectly, but then i had to map a different primary key, because the
'many-to-one"-Mapping seems not to be allowed for a 'composite-id'. The Exceptions 'says', that there is no property "uniqueKey" in classB ... but it's there ... changing only the mapping-file to 'component' makes it work.

So my questions are:
1) is there a way to use my approach with the correct
'composite-id' to define my primary-key of ClassB?

2) is there a way to set the "countryCode" dynamically and not in mapping? Perhaps using a own 'Access'-implementation?

thx in advance!
carsten


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.