How to generate database schema automatically through Hibernate
I've read that with the object mapping in place and the Hibernate configuration file set up correctly, I have everything I need to generate a script for my application by invoking the export DDL task. But I don't know where I could find it...
I'm using a mysql database, Eclipse and up until now I have created the tables by myself.
Where can I find the export DDL task?
Hiberante tools and Eclipse Plugins
OK I will post it to help you to set up all you need
BUT I have example with reverse engineering - creating code from DB.
Once you have all installed and set
I hope you will figure out easily how to do finish your work
Hiberante tools and Eclipse Plugins:
(Install manual and Reverse engineering - create code from DB example)
IN THIS FILE:
0. my installed software
1. install tools
2. create hiberanate config file
3. create hibernate console configuration and conn to DB
4. reverse eng. from DB to:
annotated java Entiry class
Hibernate XML mapping - hbm.xml
0. On my machine:
Java 1.6 SDK
MySQL JDBC Driver
1. Download "HibernateTools-3.2.4.GA-R200905070146-H18"
Download JBoss.org from SourceForge.net
Copy features to your eclipse features dir:
Copy plugins and jars to your eclipse plugins dir:
Run eclipse from command prompt with "-clean" command:
3. In Eclipse there is new 'perspective' - Hibernate.
Also there are new wizards
4. File => New => Other => Hibernate => 'Hibernate Configuration file'
Create new config file: hibernate.cfg.xml
5. Create 'Hiberante Console Configuration'
(that uses previously crated config file in step 4.)
(Done is step 4. if you checked  'Create a console configuration '
or do it manually
File => New => Other => Hibernate => 'Hibernate Console Configuration')
Create connection do some DB:
tab Main => Database connection => New => MySQL
drivers : MySQL JDBC Driver
Now switch to Hibernate perspective.
'Hiberante Console Configuration' becomes root in Hibernate Configurations window.
Right mouse click on it and click Edit to edit it more.
6. Reverse engineering - create code from DB :
Eclipse main menu Run => Hibernate code Generation => Hibernate code Generation configurations
tab Menu =>
Console Configuration - choose one created in step 5.
Outout directory: Browse and create one
Reverse eng from JDBC Connection: checked
Exporters tab= >
check Java 5 syntax for plain java syntax
Check Generate EJB3 annotations for annotaions
Click as you like
7. return to Java perspective and see cretaed Java Entity classes ant other
good luck ;)