IntelliJ IDEA Hibernate Annotations Trick

IntelliJ IDEA 6.0 features numerous enhancements for making Java EE development easier and more productive.
EJB relationship diagram builder brings valuable bonus to those who use Hibernate annotations for defining data models in their applications. All the power of the EJB diagram builder is at your disposal. You can get the complete picture of how your Hibernate entities relate one to another, and navigate through their relationships in just a couple of mouse clicks.
Hibernate Annotations
Just right-click the persistence unit where your Hibernate annotations are used and select Open ER Diagram. IntelliJ IDEA will build the relationship diagram showing entities and their relationships. Helpful tooltips are available when you hover your mouse pointer over diagram elements.
Relationship Diagram

There’s a small catch, however. If your Hibernate annotations are placed through the Java code somewhere in one of your Java (not Java EE) modules, you will need to peform some initial steps, for the diagram builder to recognize them:

  1. Create the file named persistence.xml in your module’s META-INF folder.
  2. Populate it with the stub code as follows:
    Sample Descriptor

  3. Switch to the Java EE Project View and select Java Modules from the tree. You should see the MyHibernateUnit persistence unit.
  4. Now you can build the diagram that reflects relationships between your Hibernate-annotated entities.

The latest builds of IntelliJ IDEA 6.0 where this feature is available, can be obtained through the IntelliJ IDEA EAP. The final release is scheduled to the mid of fall, 2006.

Technorati tags: , ,
Comments below can no longer be edited.

6 Responses to IntelliJ IDEA Hibernate Annotations Trick

  1. Avatar

    Stefan Arentz says:

    September 14, 2006

    It would be nice if the persistence.xml would not be in a fixed location like META-INF. Many of us develop with JPA but outside of a JEE5 container, for exampla with Spring. It is then perfectly fine to have a structure like this for example:


    In a recent project I had 3 different persistence.xml files like this as class path resources for example.

    Can something like that be added?


  2. Avatar

    Thomas Hartwig says:

    September 26, 2006

    Hi Egor, thanks for your suggestion. I would like to use this, but I have only classical java modules. I already created a dummy J2EE and put the persistence.xml file in the META-INF folder of the classical java modul as suggested. But the “MyHibernateUnit” will not be recognized. I’m not able to see the ER-diagram. Can you give a more detailed tip?

    Best regards

  3. Avatar

    Thomas Hartwig says:

    September 26, 2006

    Ok, I have found it. You must use a EJB module. I have converted my standard module to this type.


  4. Avatar

    Deepak Kumar says:

    November 19, 2006


    User Registration and Login application using Struts, Hibernate and Spring.

    Visit: http://www.roseindia.net/struts/hibernate-spring/index.shtml

    This tutorial shows how to develop User Registration and Login Application using Spring, Hibernate and Spring technologies.

    Deepak Kumar

  5. Avatar

    Oleg Mikheev says:

    April 24, 2007


    I didn’t have to create an EJB module, I have my entities in Web module and able to use EJB3 diagramming.
    You can also move your persistence.xml anywhere you like using Refactor->Move

  6. Avatar

    Bill Shirley says:

    November 1, 2007

    Looks like the hibernate annotations link has migrated locations.


Discover more