-->
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: Inheritance mapping: Accessing root class attributes/columns
PostPosted: Tue Jul 21, 2009 3:28 pm 
Newbie

Joined: Thu Jul 16, 2009 1:01 pm
Posts: 2
http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-tablepersubclass

Quote:
9.1.4. Mixing table per class hierarchy with table per subclass

You can even mix the table per hierarchy and table per subclass strategies using the following approach:

<class name="Payment" table="PAYMENT">
<id name="id" type="long" column="PAYMENT_ID">
<generator class="native"/>
</id>
<discriminator column="PAYMENT_TYPE" type="string"/>
<property name="amount" column="AMOUNT"/>
...
<subclass name="CreditCardPayment" discriminator-value="CREDIT">
<join table="CREDIT_PAYMENT">
<property name="creditCardType" column="CCTYPE"/>
...
</join>
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
...
</subclass>
<subclass name="ChequePayment" discriminator-value="CHEQUE">
...
</subclass>
</class>

For any of these mapping strategies, a polymorphic association to the root Payment class is mapped using <many-to-one>.

<many-to-one name="payment" column="PAYMENT_ID" class="Payment"/>




I have a subclass /join table setup using a discrimnator value. The join table as described needs a sub tag called key in section 9.1.3 http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-tablepersubclass

Questions:

1. Has anyone tried setting up polymorphism using the many-to-one element in the sub-class? I understand the <join table...> tag requires to have a <key> as a sub element. What if the columns in<key column..> in the sub class and <many-to-one column..> are the same. How do you get around the duplicate column issue?

2. Do you have any other strategies to access root attributes from sub classes?


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.