-->
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.  [ 2 posts ] 
Author Message
 Post subject: Class participates in two different hierarchies
PostPosted: Wed Sep 03, 2003 2:55 am 
Newbie

Joined: Wed Aug 27, 2003 1:37 am
Posts: 10
Location: Kyrgyzstan
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 5:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not supported. It is an API-level requirement of Hibernate that a class maps unambiguously to a particular table.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.