I have a pre-existing data structure in Oracle where one table is the "parent" which will join to one of a handful of "child" tables depending on what type that parent is. The sample provided in
http://docs.jboss.org/hibernate/core/3. ... tance.html is a pretty close match, where PAYMENT would be a parent table, which may join to tables (for example) CREDITCARDPAYMENT, CASHPAYMENT.
So what I'd like to do if possible is have one base class called Payment containing some common info that is in the PAYMENT table and four subclasses of that for each of the other tables.
The snag I am hitting on that I haven't found an answer for is each of these child tables has its own primary key and an associated Oracle sequence.
FYI: I can't use annotations since I'm generating the POJO classes from an XSD.
Code:
CREATE TABLE PAYMENT (
PAYMENTID INT, -- PRIMARY KEY
PAYMENTTYPE VARCHAR(10), -- will be 'CC' or 'CASH', discriminator
...
);
CREATE TABLE CREDITCARDPAYMENT (
CCPAYMENTID INT, -- PRIMARY KEY
CCPARENTPAYMENTID INT, -- FK TO PAYMENT.PAYMENTID
CCNUM VARCHAR(16),
...
);
CREATE TABLE CASHPAYMENT (
CASHPAYMENTID INT, -- PRIMARY KEY
CASHPARENTPAYMENTID INT, -- FK TO PAYMENT.PAYMENTID
...
);
each of the above has its own sequence.
Code:
<class name="Payment" table="PAYMENT">
<id name="paymentId" type="java.math.BigInteger">
<column name="PAYMENTID" precision="22" scale="0"/>
<generator class="sequence">
<param name="sequence">PAYMENTID_SEQ</param>
</generator>
</id>
<discriminator column="PAYMENTTYPE" type="string"/>
...
<subclass name="CreditCardPayment" discriminator-value="CC">
<id name="creditCardPaymentId" type="java.math.BigInteger">
<column name="CCPAYMENTID" precision="22" scale="0"/>
<generator class="sequence">
<param name="sequence">CREDITCARDPAYMENT_SEQ</param>
</generator>
</id>
<property column="CCNUM" name="ccNum" type="java.lang.String" />
<join table="CREDITCARDPAYMENT">
<key column="CCPARENTPAYMENTID"/>
</join>
</subclass>
<subclass name="CashPayment" discriminator-value="CASH">
<id name="cashPaymentId" type="java.math.BigInteger">
<column name="CASHPAYMENTID" precision="22" scale="0"/>
<generator class="sequence">
<param name="sequence">CASHPAYMENT_SEQ</param>
</generator>
</id>
<property column="... "/>
<join table="CASHPAYMENT">
<key column="CASHPARENTPAYMENTID"/>
</join>
</subclass>
</class>
the above doesn't work because the subclass doesn't allow the <id /> block. How can I define a separate ID for subclasses? I think maybe the polymorphic approach using an <any /> block might work but it's unclear to me how I'd join each separate subclass from the sample given.