Hello,
am trying to convert an existing Hibernate mapping file to annotation. I did most of the stuff, but am blocked on a complex Map property.
First of all, here is the hibernate Mapping (working well)
Code:
<class name="Employee" ....>
....
<map name="functionGroups" table="RH_EMP_FCT_GROUP_LINK" cascade="lock,merge">
<key column="EMP_ID"/>
<map-key-many-to-many column="FCT_GROUP_ID" class="be.rmi.intranet.db.users.FunctionGroup"/>
<many-to-many column="FCT_ID" class="be.rmi.intranet.db.users.Function"/>
</map>
</class>
<class name="FunctionGroupLink" table="RH_EMP_FCT_GROUP_LINK" lazy="true">
<id name="linkId">
<column name="LINK_ID" not-null="true" unique="true" />
<generator class="sequence">
<param name="sequence">RH_GENERIC_SEQ</param>
</generator>
</id>
<many-to-one name="employee" column="emp_id" not-null="true"/>
<many-to-one name="function" column="fct_id" not-null="true"/>
<many-to-one name="functionGroup" column="fct_group_id" not-null="true"/>
</class>
The table behind this is supposed to be of the following schema
Code:
create table RH_EMP_FCT_GROUP_LINK (LINK_ID bigint not null, fct_id bigint not null, emp_id bigint not null, fct_group_id bigint not null, primary key (LINK_ID))
The idea behind this table is 3-sides relation-ship between employee, function and functionGroup. Exemple entries can be "John Smith", "manager", "Sales Manager", that says the Manager of Jhon Smith is the Sales Manager. The map serves this purpose, i provide as key the "Manager" FunctionGroup, and i get the SalesManager Function as value.
I translated the Employee part of the mapping as this:
Code:
@ManyToMany()
@JoinTable(name="RH_EMP_FCT_GROUP_LINK")
@MapKey(columns=@Column(name="EMP_ID"))
@MapKeyManyToMany(joinColumns=@JoinColumn(name="FCT_GROUP_ID"))
public Map<FunctionGroup, Function> getFunctionGroups()
But for curious reason, the hbm2ddl creates the following table
Code:
create table RH_EMP_FCT_GROUP_LINK (LINK_ID bigint not null, fct_id bigint not null, emp_id bigint not null, fct_group_id bigint not null,
RH_EMPLOYEE_PERSON_ID bigint not null, functionGroups_FCT_ID bigint not null, primary key (RH_EMPLOYEE_PERSON_ID, FCT_GROUP_ID))
Am clearly missing how to tell hibernate, using annotation, what columns to use for the key and column, so if someone could correct me...