Sunday, November 1, 2009

Using MyEclipse for Hibernate projects

MyEclipse is a plugin provided by Genuitec. I use it for development of all kinds of Web applications including Hibernate, EJB2 and EJB3. MyEclipse is very up-to-date with the support of current versions of web frameworks, EJB and of course Hibernate.


  • Better to be familiar with developing web applications with J2EE
  • Knowledge on using Eclipse IDE
System Requirements

  • JDK is installed
  • MyEclipse plugin is installed
  • Oracle or other database can be used

The development work is broken down into 2 steps:

1. Adding libraries and Hibernate capabilities

Create a webproject first and open the context menu of the project (click with right mouse button on the project in the package view). Select add Hibernate capabilities.

The wizard let you select the Hibernate version and add the needed libraries to your project.

I recommend to add the libraries to the build path and not to copy them to the lib folder of the application.

This will allow to setup different configurations for deployment during development and staging.

To stage your finished application you should pack all the libraries with your project. You can configure in the project properties to deploy user libraries like the MyEclipse library in your application server.

During development, I prefer to copy all the Hibernate and struts libraries to the shared library directory of the application server. I configure the MyEclipse configuration in the project properties to not deploy any user libraries. This makes redeployment very fast.

Let’s continue with the wizard. You can select an existing Hibernate configuration file hibernate,cfg,xml or you can create a new one.

Then you can select a database connection profile for a JDBC connection or select a JNDI datasource. A connection profile is the complete configuration of a JDBC database with connection string, user name, password and DB driver.

A connection profile can be used for the database browser as well to see tables, triggers, columns. The database browser allows generating Hibernate mappings from existing tables.

Finally you can create a session factory. I prefer to use my own session factory as it is simpler but the MyEclipse session factory works perfectly as well.

2. Generate Hibernate mappings from existing db

Open the View DB Browser (MyEclipse). If you cannot find it open the “Show View” Dialog and select in the MyEclipse Enterprise Workbench the DB Browser.

Open the connection profile you specified before.

Select the tables we have just created. Right click and choose Create Hibernate Mapping.

Follow the wizard to select where to create the mapping files and classes. You can even generate DAOs.


nahrungsergänzung said...

Hibernate is a powerful, high performance object/relational persistence and query service. Hibernate lets you develop persistent classes following object-oriented idiom - including association, inheritance, polymorphism, composition, and collections. Hibernate allows you to express queries in its own portable SQL extension (HQL), as well as in native SQL, or with an object-oriented Criteria and Example API.

Anonymous said...


how can i add tables without primary Key?

Tables with primary keys, i have no problems to put it working, but with other tables i have some problems.

The process of reverse engeenering runs fine... in the end... wizard overwrites the hbm.cfg and create the necessary files(,, table.hbm.xml, etc).

When i try to use finddBy... i note that are not generated by MyEclipse. :S

any help?

sorry about my english!

Thanks in advance!

Deepanker said...

nice website.. many useful programs and tips...

Post a Comment