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: Joined-Subclass mapping on a foreign key of its parent-class
PostPosted: Thu Oct 05, 2006 4:05 am 
Newbie

Joined: Fri Mar 03, 2006 8:52 am
Posts: 5
Hello,

I'm working for about 6 months with Hibernate but I'm a newbie in creating topics in this forum. It's the first time now I do not find the right answers for my problems here, so I have to ask for it:

In my mappings I implemented table-per-subclass inheritance, but in case of my physical datamodel I was not able to implement the inheritance on a shared primary-key. So my base-class table "TerminalOwner" has foreign-key columns for each different type of "TerminalOwner". For example one foreign-key column to a "Merchant" and also one to an "Office" which are all build up in different tables.

In my case only one of these foreign-keys can be set in the "TerminalOwner" table. I know that this is a very bad model, but this model exists for years now and it would cost too much time and so money to change that (also other applications are working with this physical datamodel). It also was not implemented by me.


Hibernate version: 3.2 cr1

Mapping documents:

TerminalOwner
Code:
<hibernate-mapping>
    <class name="com.efkon.tac.mappings.TerminalOwner" table="MT_TERMINALOWNER">
        <id name="pkMtTerminalowner" type="long">
            <column name="PK_MT_TERMINALOWNER" precision="16" scale="0" />
            <generator class="assigned" />
        </id>
       
        <discriminator column="OWNERTYPE"/>

        <property name="pkMdMerchant" type="java.lang.Long">
            <column name="PK_MD_MERCHANT" precision="16" scale="0" />
        </property>
        ...
    </class>
</hibernate-mapping


Merchant
Code:
<hibernate-mapping>
    <subclass name="com.efkon.tac.test.Merchant" extends="com.efkon.tac.mappings.TerminalOwner" discriminator-value="M">
       <join table="MD_MERCHANT">
          <key column="PK_MD_MERCHANT" property-ref="pkMdMerchant"/>
           <property name="name" type="string">
               <column name="NAME" length="64" />
           </property>
        </join>
    </subclass>
</hibernate-mapping>


Name and version of the database you are using: Oracle 10g

The generated SQL (show_sql=true):

Code:
select
  terminalow0_.PK_MT_TERMINALOWNER as PK1_35_,
  terminalow0_1_.NAME as NAME44_,
  terminalow0.OWNERTYPE as clazz_
from
  MT_TERMINALOWNER terminalow0_,
  MD_MERCHANT terminalow0_1_
where
  terminalow0_.PK_MT_TERMINALOWNER=terminalow0_1_.PK_MD_MERCHANT(+)


instead of terminalow0_.PK_MT_TERMINALOWNER=terminalow0_1_.PK_MD_MERCHANT(+) this it should be:
terminalow0_.PK_MD_MERCHAND=terminalow0_1_.PK_MD_MERCHANT(+)
because table TERMINAL_OWNER includes foreign-key columns for each ownertype. In this example I only showed ownertype "Merchant".

I tested these mappings with Hibernate-Tools 3.2 beta7. Also the sql-output is from there.

I also tried it with:

Code:
<join table="MD_MERCHANT">
          <key column="PK_MD_MERCHANT" property-ref="pkMdMerchant" foreign-key="PK_MD_MERCHANT"/>


and

Code:
<join table="MD_MERCHANT">
          <key column="PK_MD_MERCHANT" foreign-key="PK_MD_MERCHANT"/>


as it is valid for the "join" element. But in every case hibernate generated the following wrong sql-query:

terminalow0_.PK_MT_TERMINALOWNER=terminalow0_1_.PK_MD_MERCHANT(+)

In my case I also have to implement this via inheritance instead of one-to-one mappings, because the logical datamodel is defined in this way.

So does anyone know if it is possible to map on a foreign-key of the parant-class instead of a shared primary-key?


Thanks in advance,
Thomas


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.