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: , ,
This entry was posted in New Features and tagged , . Bookmark the permalink.

6 Responses to IntelliJ IDEA Hibernate Annotations Trick

  1. Stefan Arentz says:

    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:

    com/test/foo/BlahRepository.java
    com/test/foo/BlahRepository-persistence.xml

    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?

    S.

  2. Thomas Hartwig says:

    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
    Thomas

  3. Thomas Hartwig says:

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

    Bye
    Thomas

  4. Deepak Kumar says:

    Hi,

    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.

    Regards
    Deepak Kumar

  5. Oleg Mikheev says:

    Thomas,

    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. Bill Shirley says:

    Looks like the hibernate annotations link has migrated locations.

    http://www.hibernate.org/397.html

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>