-->
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.  [ 14 posts ] 
Author Message
 Post subject: Reverse Engineering: Mapping file seems to be ignored
PostPosted: Tue Jul 08, 2008 1:09 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hibernate version: Hibernate Tools 3.3.2.GA, Eclipse 3.3.2 Core Plugin

I'm trying to reverse engineer a MySQL-Database with the Hibernate Tools in Eclipse.

I created a hibernate.cfg.xml that properly connects to the database. I also created and manually edited a hibernate.reveng.xml that also does a good job, fine so far. Since the hibernate.reveng.xml does not cover all I need. I set up a mapping file. Unfortunately the tools seem to completely ignore it.
  • When I explicitly include it via the Hibernate Configuration Editor code generation works but nothing from the mapping file is applicated.
  • When I manually add it to the hibernate.cfg.xml I get the same result, code generation runs but ignores the settings there.
  • If I try to expand my configuration in the Hibernate Configurations Tab I will always get a Hibernate Configuration Error that the mapping file (when manually added to the cfg.xml) cannot be found - no matter how I specify the path. It works fine, when I prepend classpath:, though!

There a
  • no errors shown in the Eclipse Error Log
  • no information in the hibernate-tools.log although log4j.logger.org.hibernate is set to debug in the hibernate-log4j.properties


Does anyone have an idea on the solution of this issue? I'd really appreciate this!

Thanx for your support!
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Solution discovered
PostPosted: Wed Jul 09, 2008 5:13 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi there,

ok, I got it now. Maybe I've overseen that somewhere or it's simply nowhere
mentioned clearly.

In the Hibernate Tools Eclipse Plug-in 3.3.2 I set up my configuration, my reverse engineering configuration and a mapping file. When I put together code generation I used to check the Reverse engineer from JDBC Connection checkbox in the Main tab. Then I selected the Exporters tab and chose Domain Code (.java). Then I ran the configuration which correctly produced the domain classes from the reveng settings.

When I also selected Hibernate XML Mappings (.hbm.xml) to be exported my handcrafted mapping files which happened to have had the name of the classes to be produced were overwritten. Then it occured to me that this was the reason I felt my mapping files would be ignored - I guess reverse engineering just overwrote the results (or reveng was higher prioritized, I don't know). After unchecking the Reverse engineer from JDBC Connection checkbox in the Main tab I received what I intended in a second run.

So I put together this little workflow for Reverse Engineering from a Database and then fine tuning the produced classes in the Hibernate Tools for Eclipse.
The pre-requisits for this to work is (besides having the hinbernate tools properly installed and have the required libraries in your path): you have your database schema set up.
  1. Switch to the Hibernate Configurations View in Eclipse.
  2. Select New > Hibernate Configuration File (cfg.xml) from the File menu and set up the configuration as described in http://www.hibernate.org/hib_docs/tools/reference/en/html/plugins.html#d0e171 (Chapters 3.2 and 3.3)
  3. When done you can check if the database connection works properly by expanding the Database entry of your configuration in the Hibernate Configurations tab. If it shows the requested schema/catalog and its tables everything should be fine.
  4. Select Run > Hibernate Code Generation... > Open Hibernate Code Generation Dialog...
  5. Follow the steps in http://www.hibernate.org/hib_docs/tools/reference/en/html/plugins.html#d0e396 (Chapter 3.4)
  6. If you need to have special settings for your reverse engineering you may specify a .reveng.xml file (refer to http://www.hibernate.org/hib_docs/tools/reference/en/html/reverseengineering.html)
  7. Don't forget to have the Reverse engineer from JDBC Connection checkbox in the Main tab checked. Optionally provide a package name and select the .reveng.xml file if you set one up.
  8. In the Exporters tab you should select the exporter for Hibernate XML Mappings (.hbm.xml).
  9. When done with all that click the Apply button. (IMPORTANT: I strongly recommend to click the Close button thereafter to close the dialog. Then you should rebuild the configuration by selecting Rebuild configuration from the context menu of your configuration in the Hibernate Configurations tab (or select the appropriate icon there). Clicking Run directly in the dialog even after the smallest change in the settings repeatedly sent my running Eclipse IDE into Nirvana.)
  10. Now re-open the Hibernate Code Generation Dialog again as described before, select your configuration and click Run. This should produce your mapping files.
  11. If you have the mapping files you can manually edit them to meet your special requirements (refer to http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html for details).
  12. When done get back to the Hibernate Code Generation Dialog. There you unselect the Reverse engineer from JDBC Connection checkbox in the Main tab and the Hibernate XML Mappings (.hbm.xml) exporter checkbox in the Exporter tab. Select instead the Domain Code (.java) exporter checkbox. Finally, click Apply, close the dialog and rebuild the configuration (see above for reasons).
  13. Once again re-open the Hibernate Code Generation Dialog again as described before, select your configuration and click Run.
  14. If the configuration was ok, you should have the files you wanted.


Unfortunately I haven't found a hint for this workflow anywhere in the documentation or in the logs in debug settings (Something like "Overwriting file x.y.z" would be nice). Don't get me wrong, I really really appreciate the huge pile of work done to get this tool to this state, but a few lines with the above content could have saved me days. (Since I haven't found anything on the internet on this issue I'm either to dumb to search for the right thing or to get the concept...). May be someone of the team likes the idea and copies some of this (in a reworked form) to the documentation.

Anyhow, keep on with the work - it's a great, powerful and helpful tool you created there! Thanx!

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 12, 2008 8:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
What you want is that reverseengineering only looks at tables for entities that is *not* already defined ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 11:41 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi,

no, I thought that the two involved steps could be done within one transparently: First, reverse engineering the classes from the database and, then, reworking the classes as I intended. I guess it's a whole lot of trouble to make this possible on the one hand side on the other it might not really make sense. I probably have had trouble getting the concept right.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what kind of "reworking" do you want that is not doable via templates ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2008 3:46 pm 
Newbie

Joined: Wed May 31, 2006 7:47 am
Posts: 6
An example would be adding some <meta ...> tags, etc. that you cannot specify in a reverse engineering file or fixing some one-off issues.


...now if I can just figure out why I cannot set the package line at the top of the generated POJO file correctly using the POJO exporter. I cannot find a non-template based way to replace // default package with the correct package name cleanly if I generate POJOs from hbm files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 2:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Pojo generation will just take the packaname from the hbm.xml file - no magic here.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 7:17 pm 
Newbie

Joined: Thu Aug 21, 2008 7:54 pm
Posts: 12
This post was immensely helpful for me, a newbie user of the Hibernate Tools in Eclipse.

I just thought I'd add two additional notes:

1. There should be a step "10.5" in the sequence above that states: "Now edit your console configuration, go to the Mappings tab, and add all of the generated mapping files". These files were not automatically picked up for me, not sure if they should have been.

2. Inheritance of "meta" tags in your mapping files is limited to the files they're defined in. I was trying to define meta attributes in a global hbm.xml expecting them to be inherited and used by each of my generated EntityA.hbm.xml files etc. So the scope of meta tag inheritance is the file the tag is declared in. The documentation says this, but I didn't read it literally / close enough the first 5 times I read it ;D.

Does anyone know of a good way to set global meta attributes that will be picked up in multiple generated hbm files? For example, I have 86 generated hbm files, but want to define a global meta attribute to set the Class comment and have them all extend a class. I'm thinking custom templates is the answer here, but confirmation would be great.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 1:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I don't have a config option for it - but you can implement a reverse engineering strategy that does it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2008 11:36 pm 
Newbie

Joined: Sun Sep 21, 2008 10:59 pm
Posts: 4
Hi, I have the same problem

i used this following configuration:
fresh extract eclipse ganymede (eclipse-reporting-ganymede-win32.zip)
HibernateTools_3.2.4.200809171643-nightly
MySQL database from XAMPP_1.6.7

i created new dynamic web project,
then hibernate configuration (it has connected to the database successfully),
then i create hibernate reverse engineering.
so far, it seems work fine.

when i try to generate code, i can't found anything code to be generated.
i did check "Reverse engineering from JDBC Connection".
no error messages, and no code generated.

this is my configuration:
Code:
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">password</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test_sdm</property>
        <property name="hibernate.connection.username">test_sdm</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    </session-factory>
</hibernate-configuration>


and here is it my hibernate reverse engineering:
(in order to make code shorter, i show only one table there)
Code:
<hibernate-reverse-engineering>
<type-mapping>
   <sql-type jdbc-type="CHAR" hibernate-type="string" not-null="false"></sql-type>
   <sql-type jdbc-type="VARCHAR" hibernate-type="string" not-null="false"></sql-type>
   <sql-type jdbc-type="TIMESTAMP" hibernate-type="timestamp" not-null="false"></sql-type>
   <sql-type jdbc-type="TINYINT" hibernate-type="java.lang.Byte" not-null="false"></sql-type>
   <sql-type jdbc-type="LONGVARCHAR" hibernate-type="string" not-null="false"></sql-type>
   <sql-type jdbc-type="BIT" hibernate-type="java.lang.Boolean" not-null="false"></sql-type>
   <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long" not-null="false"></sql-type>
</type-mapping>
<table-filter match-schema="p3sp2l_sdm" match-name=".*" exclude="false"/>
   <table catalog="p3sp2l_sdm" name="user_group">
      <column name="UserID" jdbc-type='VARCHAR'></column>
      <column name="GroupID" jdbc-type='VARCHAR'></column>
      <column name="CreatedBy" jdbc-type='VARCHAR'></column>
      <column name="CreatedDate" jdbc-type='TIMESTAMP'></column>
      <column name="CreatedHost" jdbc-type='VARCHAR'></column>
      <column name="UpdatedBy" jdbc-type='VARCHAR'></column>
      <column name="UpdatedDate" jdbc-type='TIMESTAMP'></column>
      <column name="UpdatedHost" jdbc-type='VARCHAR'></column>
   </table>
</hibernate-reverse-engineering>


am i missing something?



regards,
AriefS


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2008 11:48 pm 
Newbie

Joined: Thu Aug 21, 2008 7:54 pm
Posts: 12
Which exporters do you have selected?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 12:01 am 
Newbie

Joined: Sun Sep 21, 2008 10:59 pm
Posts: 4
i'm sorry for my post before

i'm missing something

in hibernate reverse engineering, it was

Code:
...
<table-filter match-schema="[b]p3sp2l_sdm[/b]" match-name=".*" exclude="false"/>
...


it should be

Code:
...
<table-filter match-schema="[b]test_sdm[/b]" match-name=".*" exclude="false"/>
...



but it still can't generate the code


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 12:03 am 
Newbie

Joined: Sun Sep 21, 2008 10:59 pm
Posts: 4
Exporters which i selected are :

Domain Code (.java)
Hibernate XML Mappings (.hbm.xml)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 22, 2008 3:30 am 
Newbie

Joined: Sun Sep 21, 2008 10:59 pm
Posts: 4
Hey, it works now..

i don't know what i missed before

but i do the following steps:
1. extract new fresh eclipse.
2. create hibernate configuration with com.mysql.jdbc.Driver
3. create hibernate console configuration
4. create hibernate code generation configuration
5. Export Hibernate XML first.
At the Main tab, Check "Reverse Engineer from JDBC Connection"
fill output directory, for example \testHibernate\src\com\test\db\mapping
leave package, reveng.xml, reveng.strategy blank
click Apply, then Run
6. Export Domain Code.
At the Main tab, Check "Reverse Engineer from JDBC Connection"
fill output directory, for example \testHibernate\src
fill Package com.test.db.domain
leave reveng.xml, reveng.strategy blank
click Apply, then Run
7. Now we have xml mappings at com.test.db.mapping and domain code at com.test.db.domain.

regards,
AriefS


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