Hibernate version:
3.0.5
Name and version of the database you are using:
mySQL 4.1.14
I've got my application working fine apart from one issue.
I have a many to many association between A and B. In the mapping files these are explicitly called many to many.
However, I need to store some extra information about the association. There is an extra column in the link table and the A and B thus have an extra many to one association to the link class AB.
The link table has combo of both foreign keys of A and B as the PK.
The mapping file for AB generated by middlegen includes a composite key but instead declares the only non-key property (extraInfo) in the key.
Code:
MIDDLEGEN GENERATED VERSION
<class name="AB" table="AB">
<composite-id>
<key-property name="extraInfo" type="String">
</composite-id>
<many-to-one name="A" class="A" not-null="true">
<column name = "AID">
</many-to-one>
<many-to-one name="B" class="B" not-null="true">
<column name = "BID">
</many-to-one>
</class>
<class name="A" table="A">
<id name="A" column="A" type="integer">
<set name="Bs" lazy="true" cascade="save-update" table="AB" >
<key><column name="AID"></key>
<many-to-many class="B"><column name="BID"></many-to-many>
</set>
<set name="AB" lazy="true" cascade="save-update" inverse="true">
<key><column name="AID"></key> <!-- i guess this should be composite too-->
<one-to-many class="AB"/>
</set>
</class>
similarly for B but the many-tomany to A is mapped inverse=true
If I try to correct this, (using <key-many-to-one> or putting AID and BID in <composite-id>) the application won't even start.
Code:
______ ______
A |*----------*| B |
PK:AID| |PK:BID|
______| |______|
1 1
*___________*
| AB |
|PK: AID,BID|
|extraInfo |
-------------
The problem is that when I assign an A to a B (or vice versa) a line is correctly put into the AB table but always the default value of extraInfo is saved. I have tried all sorts of different ways of changing this value, none of which work. What is the correct way to do this? Is it just a mapping issue or is there some java code that I haven't tried yet?
Thanks for your help[/code]