Hello,
I have a class called BasicProduct that is a member of the Product hierarchy, as well as the Donatable hierarchy. Here is a quick description of the hierarchy.
Code:
interface Product
class AbstractProduct implements Product
class BasicProduct extends Product implements Donatable
interface Donatable
class BasicProduct extends Product implements Donatable
class Lot implements Donatable
I want to be able to map these hierarchies so that a particular instance of BasicProduct will be included in both
Code:
select from Donatable
and
Code:
select from Product
I am having difficulty figuring out how to do this without Hibernate complaining about
Code:
net.sf.hibernate.MappingException: duplicate import: BasicProduct
Here is the relavent portions of my mapping file:
Code:
<class name="com.atwoodsoft.data.Donatable" table="Donatable">
<id name="id" type="int" column="id" unsaved-value="-1">
<generator class="native"/>
</id>
<joined-subclass name="com.atwoodsoft.data.Lot" table="Lot">
<key column="donatable"/>
<many-to-one name="product" class="com.atwoodsoft.data.Lottable" column="product"/>
<property name="lotNumber" column="lotnumber" type="string"/>
<property name="expirationDate" column="expirationdate" type="date"/>
</joined-subclass>
<joined-subclass name="com.atwoodsoft.data.Stock" table="Stock">
<key column="donatable"/>
<property name="quantity" type="int" not-null="true"/>
<property name="stockNumber" type="string" not-null="true"/>
<many-to-one name="shipment" class="com.atwoodsoft.data.Shipment" column="shipment"/>
<many-to-one name="lot" class="com.atwoodsoft.data.Lot" column="lot"/>
</joined-subclass>
<joined-subclass name="com.atwoodsoft.data.BasicProduct" table="Product">
<id name="id" type="int" column="id" unsaved-value="-1">
<generator class="native"/>
</id>
<key column="donatable"/>
<discriminator column="subclass" not-null="true"/>
<many-to-one name="manufacturer" class="com.atwoodsoft.data.Manufacturer" column="manufacturer"/>
<many-to-one name="priceSource" class="com.atwoodsoft.data.PriceSource" column="pricesource"/>
<property name="unitValue" column="unitvalue" type="int"/>
<one-to-one name="packaging" cascade="all" constrained="false"/>
<one-to-one name="name" cascade="all" constrained="false"/>
<one-to-one name="description" cascade="all" constrained="false"/>
</joined-subclass>
</class>
<class name="com.atwoodsoft.data.Product" table="Product">
<id name="id" type="int" column="id" unsaved-value="-1">
<generator class="native"/>
</id>
<discriminator column="subclass" not-null="true"/>
<many-to-one name="manufacturer" class="com.atwoodsoft.data.Manufacturer" column="manufacturer"/>
<many-to-one name="priceSource" class="com.atwoodsoft.data.PriceSource" column="pricesource"/>
<property name="unitValue" column="unitvalue" type="int"/>
<one-to-one name="packaging" cascade="all" constrained="false"/>
<one-to-one name="name" cascade="all" constrained="false"/>
<one-to-one name="description" cascade="all" constrained="false"/>
<subclass name="com.atwoodsoft.data.BasicProduct" discriminator-value="p"/>
<subclass name="com.atwoodsoft.data.Lottable">
<set name="lots" cascade="all" inverse="true" lazy="false">
<key column="product"/>
<one-to-many class="com.atwoodsoft.data.Lot"/>
</set>
<subclass name="com.atwoodsoft.data.LottedProduct" discriminator-value="l"/>
<subclass name="com.atwoodsoft.data.DrugProduct" discriminator-value="d">
<property name="dossageSize" column="dossageSize" type="int"/>
<many-to-one name="generic" class="com.atwoodsoft.data.GenericDrug" column="generic"/>
<many-to-one name="dossageUnit" class="com.atwoodsoft.data.Unit" column="dossageunit"/>
</subclass>
</subclass>
</class>
I hope that there is a best practice way of accomplishing this. If anyone has any ideas I would be very greatful.
John Atwood