0

<table schema="employees" name="dept_emp">

    <primary-key>
        <generator class="native">
     <param name="dept_emp">dept_emp_dept_no_seq</param>
    </generator>

<key-column name="dept_no" />
    <key-column name="emp_no" />

    </primary-key>

   <column name="from_date" property="fromDate" type="date" />
   <column name="to_date" property="toDate" type="date" />
</table>


<table schema="employees" name="employees">

 <primary-key>
       <generator class="native">
     <param name="employees">employees_emp_no_seq</param>
       </generator>

   <key-column name="emp_no" />

 </primary-key> 

   <column name="birth_date" property="birthDate" type="date" />
   <column name="first_name" property="firstName" type="string" />
   <column name="last_name" property="lastName" type="string" />
   <column name="gender" property="Gender" type="string" />
   <column name="hire_date" property="hireDate" type="date" />

</table> 

Is there way I can modify my hibernate.reveng.xml file for 2tables with composite keys having object references in the POJOs The above file is reveng.xml that I need to modify to automatically generate the POJOs with object reference in them (column name = emp_no)

Beto
  • 1
  • 2

1 Answers1

0

You can add below table declarations in your reveng.xml then your pojos will be generated with expected relations.

<table schema="employees" name="dept_emp">

    <composite-id name="id" class="com.hrdb.DeptEmpId">
            <key-property name="empNo" type="string">
                <column name="emp_no" length="3" />
            </key-property>
            <key-property name="deptNo" type="string">
                <column name="dept_no" length="3" />
            </key-property>
        </composite-id>
        <many-to-one name="employees" class="com.hrdb.Employees" update="false" insert="false" fetch="select">
            <column name="emp_no" length="3" not-null="true" />
        </many-to-one>

   <column name="from_date" property="fromDate" type="date" />
   <column name="to_date" property="toDate" type="date" />
</table>

You can use git hub project to generate HBM file out of Database configuration.From the hbm file it is easy to construct reveng.xml file.

Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38