FFL2:FFL2 Main/Hibernate Reverse Engineering: Difference between revisions

From FFL Wiki
Jump to navigation Jump to search
Replaced content with 'To reverse engineer the hibernate mappings and objects from the schema some additional setup is required. Hibernate Reverse Engineering Config'
Line 1: Line 1:
To reverse engineer the hibernate mappings and objects from the schema some additional setup is required.
To reverse engineer the hibernate mappings and objects from the schema some additional setup is required.


Note that in this example a VMWare image is being used to run MySQL, this is because MySQL is case-insensitive on Windows and always returns table names in lower case.  This causes two problems
[[Hibernate Reverse Engineering Config]]
# Generated class names won't be capitalised as we would like
# The generated config won't work on Linux
 
== Install Hibernate Tools Eclipse plugin ==
* The update URL is http://download.jboss.org/jbosstools/updates/stable/
* The installation procedure is the same as that described for the SVN plugin at [[../Dev_Environment/Install_Subclipse_Eclipse_plugin]] except that only the 'Hibernate Tools' component under 'JBoss Tools' is required. Don't install the full 'JBoss Tools' suite.
 
== Create a Hibernate configuration in Eclipse ==
 
Open the Hibernate perspective then right-click and choose 'Add Configuration...' in the Hibernate Configurations view. Set up the 'Main' and 'Options' tabs as shown below
 
[[File:Eclipse Hibernate Config Main.png]]
 
[[File:Eclipse Hibernate Config Options.png]]
 
 
 
When creating the database connection under 'Main' using the 'New...' button, the JAR file for the driver to use needs to be specified by clicking the triangle next to the 'Drivers' drop-down
 
[[File:Eclipse Hibernate Driver Properties.png]]
 
[[File:Eclipse Hibernate Driver Definition.png]]
 
Finally, click 'Test Connection' to check it is ok.
 
 
== Create the Reverse Engineering Configuration ==
 
Choose 'Run | Hibernate Code Generation | Hibernate Code Generation Configurations...' and create a new 'Hibernate Code Generation' configuration called 'Reverse Engineer FFL Model from DB'.  Configure the 'Main' and 'Exporters' tabs as shown below. 
 
There are a couple of points to note:
 
# We use and output directory of \fantacycore\hibernate_gen_src to avoid overwriting our existing code.  We will merge in the changes we want.
# uk.org.fantacy.reveng.FantacyReverseEngineeringStrategy is a custom reverse engineering strategy which was written to make sure the generated one-to-many and many-to-many associations have appropriate names.  If you add a new table whose name would not be made plural by simply adding 's' (e.g. history -> histories) then you may need to update this.
# The output directory of the XML config exporter is set to \fantacycore\hibernate_gen_src to avoid overwriting our existing config.  No special properties are set on any other exporters.
 
[[File:Hibernate Reverse Engineer Config Main.png]]
 
[[File:Hibernate Reverse Engineer Config Exporters.png]]

Revision as of 08:55, 8 January 2011

To reverse engineer the hibernate mappings and objects from the schema some additional setup is required.

Hibernate Reverse Engineering Config