Hello!
Suppose I have a many-to-many realtion between the two classes A and B. The association itself has an attribute, so I decide to model the association as an association-class C.
Now I decided to map this scenario with the approach recommended in the Hibernate Reference (chapter 7.2): "A special case of a composite element is a composite element with a nested <many-to-one> element. A mapping like this allows you to map extra columns of a many-to-many association table to the composite element class."
Here is my example mapping approach:
Code:
<class name="A" table="A">
<id name="id" column="ID" />
<generator class="uuid.string" />
</id>
<property name="some_property_A" />
</class>
<class name="B" table="B">
<id name="id" column="ID" />
<generator class="uuid.string" />
</id>
<property name="some_property_B" />
<list name="listOfCs" table="LIST_OF_Cs">
<key column="B_ID" />
<index column="INDEX" />
<composite-element class="C">
<property name="some_property_C" />
<many-to-one name="link_to_A" class="A" />
</composite-element>
</list>
</class>
So I have three classes A, B and C, where C is the only one, that has no "id"-attribute.
Now my question: do I need to declare a mapping for class "C"? Is it right, that I have 3 classes but only two mapping files (one for "A" and one for "B")?
"C" actually is my component-class. The class "C" has two attributes "some_property_C" and "link_to_A" with appropiate getters and setters.
The schema-export of this mapping works fine, the right tables are created, but I cannot save an entity of B, when I try to execute the following code (initialization of Configuration, Connection and SessionFactory are not shown in the code):
Code:
B b = new B();
b.setSome_Property_B("A String");
b.setListOfCs(new ArrayList());
sess.save(b);
An Exception is thrown, when trying to execute "sess.save(b)". Unfortunately the exception message does not show much information about what is going on, because my application throws a new Exception, when catching the HibernateException.
Another thing to be mentioned is that I use interfaces for the classes "A", "B" and "C" and my mapping actually is based on the mapping of interfaces. I just add the <subclass>-tag to declare the implementing classes of these interfaces.... but adding an interface layer is not the source of my problem I guess...
Thx in advance!
Philipp Hinnah