Member Menu
 
 Monthly JBoss newsletter:
 
Hibernate Books
CaveatEmptor

IntelliJ User Info

Maven

I'd highly recommend using IntelliJ 7 or higher with the built-in Maven support, at least for the versions of Hibernate built using Maven. Using that one can simply point IntelliJ at the Maven pom.xml file and have the project setup within IntelliJ automatically. The tips and instructions below will assume use of IntelliJ 7.

Source header

Source Code Header remains the authoritative version of the header to use...

I found working with source headers in IntelliJ absolutely painless using the Copyright plugin obtained via the plugin manager. Here is the text I told the Copyright plugin to use:

Hibernate, Relational Persistence for Idiomatic Java

Copyright (c) $today.year, Red Hat Middleware LLC or third-party contributors as 
indicated by the @author tags or express copyright attribution 
statements applied by the authors.  All third-party contributions are 
distributed under license by Red Hat Middleware LLC.

This copyrighted material is made available to anyone wishing to use, modify,
copy, or redistribute it subject to the terms and conditions of the GNU
Lesser General Public License, as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
for more details.

You should have received a copy of the GNU Lesser General Public License
along with this distribution; if not, write to:
Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor
Boston, MA  02110-1301  USA

Codestyle

Here is the IntelliJ codestyle used by the Hibernate developers using IntelliJ. Simply copy the below text into a file called ${IDEA_HOME}/config/codestyles/hibernate.xml and specify 'hibernate' as the codestyle to use (the below was generated using IntelliJ version 7.0.1):

<?xml version="1.0" encoding="UTF-8"?>
<code_scheme name="hibernate">
  <option name="USE_SAME_INDENTS" value="false" />
  <option name="JAVA_INDENT_OPTIONS">
    <value>
      <option name="INDENT_SIZE" value="4" />
      <option name="CONTINUATION_INDENT_SIZE" value="8" />
      <option name="TAB_SIZE" value="4" />
      <option name="USE_TAB_CHARACTER" value="true" />
      <option name="SMART_TABS" value="false" />
      <option name="LABEL_INDENT_SIZE" value="0" />
      <option name="LABEL_INDENT_ABSOLUTE" value="false" />
    </value>
  </option>
  <option name="ELSE_ON_NEW_LINE" value="true" />
  <option name="CATCH_ON_NEW_LINE" value="true" />
  <option name="FINALLY_ON_NEW_LINE" value="true" />
  <option name="SPACE_WITHIN_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_METHOD_CALL_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_IF_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_WHILE_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_FOR_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_CATCH_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_SWITCH_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_SYNCHRONIZED_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_CAST_PARENTHESES" value="true" />
  <option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
  <option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
  <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
  <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
  <option name="IMPORT_LAYOUT_TABLE">
    <value>
      <package name="java" withSubpackages="true" />
      <package name="javax" withSubpackages="true" />
      <emptyLine />
      <package name="" withSubpackages="true" />
      <emptyLine />
      <package name="org.hibernate" withSubpackages="true" />
    </value>
  </option>
  <option name="CALL_PARAMETERS_WRAP" value="5" />
  <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
  <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
  <option name="EXTENDS_KEYWORD_WRAP" value="1" />
  <option name="THROWS_KEYWORD_WRAP" value="1" />
  <option name="METHOD_CALL_CHAIN_WRAP" value="5" />
  <option name="FOR_STATEMENT_WRAP" value="5" />
  <option name="ARRAY_INITIALIZER_WRAP" value="5" />
  <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
  <option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
  <option name="IF_BRACE_FORCE" value="3" />
  <option name="DOWHILE_BRACE_FORCE" value="3" />
  <option name="WHILE_BRACE_FORCE" value="3" />
  <option name="FOR_BRACE_FORCE" value="3" />
  <option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
  <option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
  <option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
  <option name="XML_ATTRIBUTE_WRAP" value="4" />
  <ADDITIONAL_INDENT_OPTIONS fileType="js">
    <option name="INDENT_SIZE" value="4" />
    <option name="CONTINUATION_INDENT_SIZE" value="8" />
    <option name="TAB_SIZE" value="4" />
    <option name="USE_TAB_CHARACTER" value="false" />
    <option name="SMART_TABS" value="false" />
    <option name="LABEL_INDENT_SIZE" value="0" />
    <option name="LABEL_INDENT_ABSOLUTE" value="false" />
  </ADDITIONAL_INDENT_OPTIONS>
</code_scheme>

Debugging

The debugger integrated into IntelliJ allows the user to specify exactly how objects get rendered through what it terms 'Type Renderers'. One point where this is really nice when debugging with Hibernate is in the case of lazy objects. We don't want the simple fact that a lazy proxy is being displayed in the debugger to force the proxy to initialize; especially if we happen to be debugging a lazy loading problem ;) To set up rendering in the debugger appropriately, open up the debugger configuration panel (IDE Settings > Debugger). There you are presented with 2 tabs: 'General' and 'Type Renderers'.

General tab

Bbe sure that the "Enable 'toString()' object view" option is disabled. In general, disable anything that would cause the debugger to force initialization of the proxy.

Type Renderers tab

We will add 2 custom type renderers: one for entity proxies and one for lazy collections.

Entity Proxy renderer

FQN : org.hibernate.proxy.HibernateProxy

Rendering Node : expression : ((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().isUninitialized() ? ( ((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().getEntityName()+"@"+System.identityHashCode(this)+"[proxy;id="+((org.hibernate.proxy.HibernateProxy)this).getHibernateLazyInitializer().getIdentifier()+"]" ) : this.toString()

Expanding Node : default (this will force the proxy to initialize if the user attempts to expand the node)

Collection renderer

FQN : org.hibernate.collection.AbstractPersistentCollection

Rendering Node expression : ((org.hibernate.collection.AbstractPersistentCollection)this).wasInitialized() ? this.toString() : ( ((org.hibernate.collection.AbstractPersistentCollection )this).getClass().getName()+"@"+ System.identityHashCode(this)+" [uninitialized]" )

Expanding Node : default (this will force the proxy to initialize if the user attempts to expand the node)

© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]