Lets take a look at some graphical step by step procedure to generate java annotated entities from the already available database tables. This can be achieved using Hibernate Tools from JBoss.
Here are some pre-requisites to be taken care of
Setup:
1. JBOSS Tools eclipse update site
http://download.jboss.org/jbosstools/updates/stable/kepler/
2. Search & Select hibernate tools from the listing
3. Install Hibernate tools
4. Download the hibernate dependencies
http://sourceforge.net/projects/hibernate/files/hibernate4/4.2.7.Final/
Install the Hibernate Tools from the eclipse Install New Software option and go on selecting and accepting the next options:
Lets start by creating a basic JPA project and set it up for magic.
1. Create a new JPA project and add JPA facet configuration
Create e new JPA project
Select the JPA Facet as Hibernate JPA. Disable JPA configuration
Add a MySQL connection profile and test it for connectivity to your database
Add the MySQL driver and also Select annotated discovery of beans. The final facet page will look like this:
2. Add hibernate dependencies to the build path
Go to the java build path configuration from project properties. Make sure you have downloaded the relevant dependencies and configured it as below.
The final project structure shall look as per the below snapshot
3. I did get a classpath error and I found that I should not be using JPA but core as a Hibernate setting console configuration
Error: [Classpath]: Could not create JPA based Configuration
Solution: Go to the Hibernate Settings from project properties and select details on your console configurations and set it as per the snapshot here.
4. Generate the entities from the table in your configured database
This is the final step where you generate the java entities by selecting the JPA tools option
Here you have to select the package the generated entities should target along with the console configuration that we already setup before.
As soon as you click Finish here the processing starts and the package should get populated with entities mapped to the tables in the configured database.
We get the generated User.java entity bean here
This is a great help to kickstart your development you wont want to really start writing each annotation and associations manually.
GitHub Link: https://github.com/vishwakarmarhl/HibernateTests.git