I am trying to map multiple tables - an ALLERGY table and an ALLERGY_AUDIT table that is updated by triggers when changes are made in the ALLERGY table - and would like to map both tables to an abstract class and its concrete descendants.
Here are the table definitions:
CREATE TABLE ALLERGY (
ALLERGY_KEY INTEGER NOT NULL,
ALLERGY_TYPE CHAR(1) NOT NULL,
SEVERITY CHAR(1) NOT NULL,
DRUG_CODE VARCHAR(10)
);
CREATE TABLE ALLERGY_AUDIT (
ALLERGY_KEY INTEGER NOT NULL,
ALLERGY_TYPE CHAR(1) NOT NULL,
SEVERITY CHAR(1) NOT NULL,
DRUG_CODE VARCHAR(10),
DATE_MODIFIED TIMESTAMP NOT NULL
);
And here is the current Hibernate mapping file for the ALLERGY table to either the DrugAllergy or NonDrugAllergy class:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.mycompany.allergy.Allergy"
table="ALLERGY">
<id
column="ALLERGY_KEY"
type="integer">
<generator class="sequence">
<param name="sequence">ALLERGY_SEQ</param>
</generator>
</id>
<discriminator
type="java.lang.String"
column="ALLERGY_TYPE"
insert="false"
not-null="true" />
<property
name="severity"
column="SEVERITY"
type="java.lang.String"
length="1" />
<subclass
name="com.mycompany.DrugAllergy"
discriminator-value="D">
<property
name="drugCode"
type="java.lang.String"
column="DRUG_CODE"
length="10" />
</subclass>
<subclass
name="com.mycompany.NonDrugAllergy"
discriminator-value="N">
<!-- No additional properties -->
</subclass>
</class>
</hibernate-mapping>
I know that in order to map the ALLERGY_AUDIT table to the Allergy class and its two concrete subclasses that I can use the entity-name property, but I have not yet found a full example of how this is accomplished. Can someone please provide a full example of the mapping file as an example?
TIA.[/i]
|