Saturday, August 13, 2011

Hibernate Tools in Eclipse

Hibernate Tools in Eclipse

I am a NetBeans user and am attempting to learn to use Eclipse.

The Hibernate Tools have a package for Eclipse, but I have not found one for NetBeans. This is why I am trying to learn Eclipse.

Eclipse and Ubuntu follow a similar naming device for versions. Eclipse is now up to Indigo. The previous version was Helios.

I have installed Indigo.

I am reading a page about using the JBoss Update link.

I have gone to Help -> Install New Software, selected Web and EE Developement and then Hibernate Tools. After a license screen, the tools installed. The install site is JBoss Tools Requirements - Composite Indigo RC2 Mirror - http://download.jboss.org/jbosstools/updates/indigo/RC2/

When I open the New wizard, I see the Hibernate wizards. So far so good.

I have create a new Dynamic Web Project and will now try to reverse engineer some POJO classes from my database using the Hibernate Tools.

I am following the instructions for reverse engineering POJO files.
  1. Create hibernate config file (File Name: hibernate.cfg.xml)
  2. Parent folder: HibernateReverse/src
  3. Using mysql and com.mysql.jdbc.Driver. (I do not know if this will be found, but it appeared in drop down list. In Helios, this driver did not appear.)
  4. Creating console configuration, for accessing the database without using code. The console allows me to see all the tables, etc, in the database. Good news, the wizard page has the correct appearance from the tutorial. When I tried this before (without JBoss update) the wizard was different.
  5. Added Hibernate Perspective.
  6. Tried to open console configuration, but db driver could not be found (I told you so).
  7. I will try adding an external jar. Opened project properties, selected Build Path, selected Add External Jar, pointed to the driver jar. It worked!!!
  8. I opened the console configuration and am able to view all the tables in the database.
  9. Starting the Hibernate Configuration wizard. There is a new icon for running hibernate and there is a new option under the Run menu.
  10. Double-clicked Hibernate Code Generation to get a new config. Set output folder.
  11. Select Reverse Engineer from JDBC.
  12. Create new Reverse.eng.xml. Include table(s) to process.
  13. Selected Java 5, EJB3 Annotations and Domain code. I did not select a config file option. I think that the annotations will be enough.
  14. Refresh tab: refresh workspace.
  15. Common tab: no change.
  16. Click Run. It worked!!!
Trying again a month later. Needless to say, I have forgotten everything, so I started playing around.

Once the Hibernate tools are added, there is a new icon in the tool strip. It is a green, play arrow like the other Run configurations, but it is for Hibernate. To do a reverse engineering process, select Hibernate Code Generation Configurations from that list. This option is also available at the bottom of the normal Run tool icon.

First create the console configuration for connecting to the database, then create a Hibernate Reverse Engineering configuration. The reverse engineering file can be created from there.

No comments:

Post a Comment

Followers