-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Middlegen: many-to-many w/ field in assoc table
PostPosted: Tue Jun 01, 2004 7:42 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 9:36 am
Posts: 28
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 8:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Did you try to set the generator attribute to true on the jointable tag?
Maybe you did - not sure what 'standard table generation' meant.

Anyway, if this is not appropriate then please show me what your expecting the mapping to be.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 01, 2004 8:51 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 9:36 am
Posts: 28
David,

Thanks for quick reply. That'll do just fine.

Thanks again,
Tyler


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.