I currently have two tables and I am trying to use the discrimintor to get 3 different sets based on the animal_type_code.
Table A
id (primary key)
animal_code
animal_type_code
The hbm.xml file looks something like
<class name="Animal" table="Table A">
<id name="ID" column="Id">
<generator class="native" />
</id>
<discriminator column="animal_type_code " />
<subclass name="Dog" discriminator-value="D">
</subclass>
<subclass name="Cat" discriminator-value="C">
</subclass>
<subclass name="Pig" discriminator-value="P">
</subclass>
</class>
In my other hbm.xml file, I am trying to get a set that contain only Dogs, a set that contains only Cats, and a set that contain only Pigs. However, i don't know how to map this. I tried something similar but I noticed that you can't have a reference to the same column. This what I was trying to do but it doesn't work
<set name="dogs" table="table A" inverse="true" lazy=false>
<key column="id"/>
<many-to-many column="animal_code" class="Animal"/>
</set>
<set name="cats" table="table A" inverse="true" lazy=false>
<key column="id"/>
<many-to-many column="animal_code" class="Animal"/>
</set>
<set name="pigs" table="table A" inverse="true" lazy=false>
<key column="id"/>
<many-to-many column="animal_code" class="Animal"/>
</set>
And in the java file I have three sets defined along with getters and setters as such:
private Set<Dog> dogs;
private Set<Pig> pigs;
private Set<Cat> cats;
Can someone please give me an idea how I should probably map the files to get the results that I am trying to receive. Thanks
|