Hello.
I have a many-to-any mapping but the association table that schema export generates is wrong (see below):
Hibernate version:
3.0.5
Mapping documents:
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">
<hibernate-mapping package="mypackage">
<class
name="Task"
table="task"
proxy="Task"
>
<id name="id" type="java.lang.Long" column="id">
<generator class="native"/>
</id>
<version name="version" column="version"/>
<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="250"
>
<!-- uni-directional many-to-any association -->
<set
name="taskObjects"
lazy="true"
cascade="none"
table="task_obj_assoc"
>
<key column="task_id"/>
<many-to-any id-type="long">
<column name="ref_type"/>
<column name="ref_id"/>
</many-to-any>
</set>
</class>
</hibernate-mapping>
Name and version of the database you are using:
MySQL 4.1.12 (InnoDB)
The generated "task_obj_assoc" table has the following structure:
+------+ +---------------------+
| task | | task_obj_assoc |
+------+ +---------------------+
| id | <-------> | task_id (PK) (FK) |
| | | ref_type |
+------+ | ref_id |
+---------------------+
The problem is that the id of task_obj_assoc should be a composite key (made out of task_id, ref_type and ref_id) not just task_id (it's a not a many-to-many relationship anymore but 1 (task side)-to-many).
Is this a bug or am I missing something here? Is there a workaround or is my mapping incorrect? I have searched the tests/docs/forum plus DTD and I couldn't find another attribute/element to add.
Thanks!