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: JavaEE, Hibernate, IntelliJ
image description