Hello. I'm new to Hibernate and I seem to be having trouble getting Hibernate to correctly reverse engineer a MySQL database into Java classes.
In my employees database I have several tables:
employees (primary key emp_no)
departments (dept_no)
salaries (composite keys emp_no and from_date)
dept_emp (composite keys dept_no and emp_no)
The problem is that when I reverse engineer the table (config and reveng files below), instead of creating the 4 java classes, Hibernate is giving me 6 java classes with extra ones
bolded:
Employees
Departments
Salaries
SalariesId
DeptEmp
DeptEmpId
As far as I can tell, for the tables with composite primary keys, Hibernate is creating a new
____Id class that contains the two composite keys. The intended behavior would have key and a set of the other related objects (DeptEmp would have a department and a set of employees within that department).
Any Ideas how I can get Hibernate not to do this? I've been trying lots of things in the .reveng file, and nothing seems to be working.
Reverse Engineering File:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<table-filter match-catalog="employees" match-name="departments" />
<table-filter match-catalog="employees" match-name="dept_emp" />
<table-filter match-catalog="employees" match-name="employees" />
<table-filter match-catalog="employees" match-name="salaries" />
<table schema="employees" name="departments">
<primary-key>
<key-column name="dept_no" />
</primary-key>
</table>
<table schema="employees" name="employees">
<primary-key>
<key-column name="emp_no" />
</primary-key>
</table>
<table schema="employees" name="salaries">
<primary-key>
<key-column name="emp_no" />
<key-column name="from_date" />
</primary-key>
</table>
<table schema="employees" name="dept_emp">
<primary-key>
<key-column name="emp_no" />
<key-column name="dept_no" />
</primary-key>
</table>
</hibernate-reverse-engineering>
Configuration File:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/employees</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">****</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.pool_size">20</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
</session-factory>
</hibernate-configuration>