barnesjd wrote:
kamalsofteng wrote:
Thanks for the note.
My problem is that I am inside a subclass mapping. Assume you have product abstract and in one if its implementations classes, you have that collection!
I have to create a join element of the subclass but don't know how to make the many-many join table.
The subclass does not have any other properties, but a list of parent class objects.
Take a second look at my previous post. I showed a mapping of the class Product with Bundle as a subclass. The class of the objects contained in your collection only needs to be mapped. The relationship of that class to the class containing the collection is immaterial.
On the other hand, you would have an issue with my mapping because I declared the list as one-to-many. I believe if you just change it to many-to-many it should just work. If it doesn't, post the error so I have a better idea of why you're having problems.
Joe
Thanks Joe;
It seems like I am getting almost there. I went back to my classes and after a few back and forth, I changed the xml file to look like this:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 31, 2009 1:40:56 PM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping default-access="field">
<class name="test.ProductDefinition" table="PRODUCT_DEFINITIONS" abstract="true">
<id name="id">
<column name="id" />
<generator class="native" />
</id>
<property name="description" type="string">
<column name="DESCRIPTION" />
</property>
<property name="orderMultiple" type="int">
<column name="ORDER_MULTIPLE" />
</property>
<property name="price" type="float">
<column name="PRICE" />
</property>
<property name="billingID" type="string">
<column name="BILLING_ID" />
</property>
<subclass name="test.Print" discriminator-value="PRINT" >
<join table="PRINTS">
<key column="PRINT_ID"></key>
<property name="width" type="float" column="width"></property>
<property name="height" type="float" column="height"></property>
<property name="printLayoutID" column="print_layout_id" type="string"></property>
</join>
</subclass>
<subclass name="test.Bundle" discriminator-value="BUNDLE" >
<set name="products" table="BUNDLE_PRODUCTS">
<key column="PARENT_ID"></key>
<many-to-many class="test.ProductDefinition" column="CHILD_ID"></many-to-many>
</set>
</subclass>
</class>
</hibernate-mapping>
However, this time it gives me an error that does not seem to make sense:
Code:
org.hibernate.MappingException: No discriminator found for test.Print. Discriminator is needed when 'single-table-per-hierarchy' is used and a class has subclasses
And if you see, I have discriminator values for both subclasses!