Generate entity classes with Hibernate Tools

Share

I recently gave a try to reverse engineering a database into entity classes by using Hibernate Tools. And it is quite cool.

Hibernate Tools is a toolset for Hibernate 3 which is part of JBoss Tools, an umbrella project for a set of Eclipse plugins.
At first, I am using Eclipse Helios, and I installed the plugin by searching inside Eclipse market for Jboss Tools and installed the Hibernate Tools plugin alone.

There are 2 steps that you have to follow in order to automatically generate entity classes from a database

  • Create a Hibernate console configuration
  • – for this you need to have a project with a hibernate.cfg.xml file, where you specify the connection parameters. This is an xml file where you need to specify some properties to be used by hibernate to create a connection to the database you specify. For more information about the properties that can go here, take a look inside the hibernate documentation
    After creating the hibernate.cgf.xml file, you can right click now on the project folder and choose New->Hibernate Console Configuration and hit Finish.
    If you switch now to the Hibernate perspective, you can see this new console configuration

  • Reverse engineer
  • – After installing the Hibernate Tools plugin you can find this option using the Hibernate perspective and find it under Hibernate run menu

      A wizard pops up and we have to choose a folder which represents the destination for the generated files. Also, there is a “reveng.xml” file that needs to be provided, so we choose the “create a new file” option inside the setup dialog.

      We choose the current project, and we see a window asking us to choose the tables that will be reverse engineered. In order to actually see the tables, we have to click the Refresh button

      Now we make our selection and hit the Include button.
      The next step is to choose from the Exporters tab the “Domain code” option and hit Run


      Now we should see the generated classes inside the chosen folder.

      Hibernate Tools also has some other nice features like a HQL and a criteria editor where you can run queries and inspect the resulting objects. Check them out here

      Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close