I was wondering if there's a way to inform the middlegen-hibernate plugin to generate a many-to-many relationship using an association table that contains extra fields.
Example:
table: employees (employee_id (int), etc.)
table: department (department_id (int), etc.)
table: employees_departments (employee_id, department_id, manager (bool) )
Using the code below results in middlegen skipping the manager field.
Code:
<many2many>
<tablea generate="true" name="employees"/>
<jointable name="employees_departments" generate="false"/>
<tableb generate="true" name="departments"/>
</many2many>
I know the suggested way of doing this is with a composite-element, but I don't know how to get middlegen to produce the composite-element and when I do it by hand I end up with 2 java files, because I have to create two unique composite-elements (ManagedEmployee and ManagedDepartment).
Deparments.hbm.xml contains...
Code:
<set
name="managedEmployees"
lazy="true"
table="employees_departments"
cascade="all"
>
<key>
<column name="department_id" />
</key>
<composite-element class="com.warfrog.sterling.brokeronline.hibernate.ManagedEmployee">
<property
name="manager"
type="java.lang.Boolean"
column="manager"
not-null="true"
length="1"
/>
<many-to-one name="employee" class="com.warfrog.sterling.brokeronline.hibernate.Employee">
<column name="employee_id"/>
</many-to-one>
</composite-element>
</set>
and Employee.hbm.xml contains
Code:
<set
name="managedDepartments"
lazy="true"
table="employees_departments"
cascade="all"
inverse="true"
>
<key>
<column name="employee_id" />
</key>
<composite-element class="com.warfrog.sterling.brokeronline.hibernate.ManagedDepartment">
<property
name="manager"
type="java.lang.Boolean"
column="manager"
not-null="true"
length="1"
/>
<many-to-one name="department" class="com.warfrog.sterling.brokeronline.hibernate.Department">
<column name="department_id"/>
</many-to-one>
</composite-element>
</set>
Additionally, using the standard table generation results in middlegen creating an hbm.xml for the employees_departments table and I can't seem to get the cascading / inversions correct to generate the correct saving behavior.
Thank you in advance,
Tyler