-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Reverse Engineering Creates extra "ClassId" class
PostPosted: Fri Sep 26, 2014 12:08 pm 
Newbie

Joined: Thu Sep 25, 2014 5:10 pm
Posts: 2
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>


Last edited by bph8ae on Tue Sep 30, 2014 1:22 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Reverse Engineering Creates extra "ClassId" class
PostPosted: Mon Sep 29, 2014 12:50 pm 
Newbie

Joined: Mon Sep 29, 2014 12:45 pm
Posts: 1
I am having the same issue with Hibernate Reverse Engineering, Is there any ideas about the fix


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.