-->
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: Sample mapping file for mapping multiple tables to one class
PostPosted: Mon May 16, 2005 5:43 pm 
Newbie

Joined: Mon May 16, 2005 5:36 pm
Posts: 1
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]


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.