Skip to content

Debugging the Hibernate project with Eclipse

Trying to debug projects made using Apache Maven has not been something achieved with any success.

Having been working at the periphery of the Hibernate source and submitting simple patches for the Ingres dialect and some tests I am now in a position to start debugging some of the issues discovered whilst testing. I have been dabbling with building maven projects from Eclipse using m2eclipse, but have not managed to perform source level debugging. I found this article Dealing with the Eclipse IDE that provides some clues on how it is done.

Essentially it involves a remote debug session from a container project to a running maven goal configured to listen.

Versions

The versions of software that I’ve been playing with

  • Eclipse Galileo ~SR1 – Build id: 20090920-1017
  • Eclipse Helios M5 – Build id: 20100204-0846 (I started to install the m2eclipse plugin and import the projects, but needs more work)
  • Ingres 9.3.1 (int.lnx/106)
  • java version “1.6.0_16″
  • mvn Apache Maven 2.2.1 (r801777; 2009-08-06 20:16:01+0100)
  • Apache Ant version 1.7.1 compiled on June 27 2008
  • Hibernate 3.5.0-Final
  • Path: .
    URL: http://anonsvn.jboss.org/repos/hibernate/core/tags/hibernate-3.5.0-Final
    Repository Root: http://anonsvn.jboss.org/repos/hibernate
    Repository UUID: 1b8cb986-b30d-0410-93ca-fae66ebed9b2
    Revision: 19149
    Node Kind: directory
    Schedule: normal
    Last Changed Author: steve.ebersole@jboss.com
    Last Changed Rev: 19148
    Last Changed Date: 2010-03-31 18:38:55 +0100 (Wed, 31 Mar 2010)

These notes assume that the software has been installed and configured. For example, the Maven local repository location is available and that the Maven remote repository is accessible.

Installing m2eclipse

The article Dealing with the Eclipse IDE includes links on how to install m2eclipse, but in summary, to install new software in Eclipse use the built-in update manager:

  • Using the menus select
    • Help > Install New Software
    • In the dialog add the URL http://m2eclipse.sonatype.org/sites/m2e
    • Check the boxes of the packages that should be installed
      • NB” Version 0.9.8 should be un-installed before upgrading to 0.10.

Import the Hibernate project

Once the m2eclipse extensions have been installed into Eclipse the preparation for importing the Hibernate Project Object Model (POM) XML file into the IDE is complete. Importing the Hibernate project is optional and is only required if you intend to build Hibernate from Eclipse. The remote Java application perspective will connect to either a command line invoked maven process or an Eclipse invoked maven process.

  • Start Eclipse
    • Create a new workspace for the Hibernate project.
  • Using the menu File > Import
    • Select Maven > Existing Maven Projects
    • Click Next and use the browse button to specify the root directory of the Hibernate source code, this is the directory in which the top level pom.xml file exists.
    • The sub-projects appear in the tree view in addition to the hierarchy beneath the top level project.
  • Import Exisiting Maven Project

The initial import and build of the workspace can take a while.

Create a Surefire Debug Configuration

Create a run configuration for a specific test class for debugging. In this example the filter.DynamicFilterTest has been cut down into filter.IngresDynamicFilterTest.

  • Select the menu Run > Run configuration option or from the context menu using a right click.
  • In the Run Configuration dialog select ”maven” and create a new configuration
    • Enter a name for the configuration
    • Surefire Debug
    • Set the base directory to the test suite directory by browsing the file system
    • Set the goals
    • test -Dmaven.surefire.debug
    • Use a JDBC profile if one is required and has been configured
    • Set the ”test” parameter to a specific test class intended for debugging
      • test=org.hibernate.test.filter.IngresDynamicFilterTest
  • Maven Test Run Configuration

Create a Debugging Container Project

The container java project does not contain any source and is used as the launch point for a remote debugging configuration.

  • Using the File->New->Project->Java Project (or equivalent)
  • Set the project name in the wizard
  • Project Name: Maven Debug and finish
  • In order to debug a maven project a container project is used to connect to maven in debug mode.

    Create Container Project from Ray Fan on Vimeo.

  • Use the Run->Debug Configurations menu to create a configuration for the Remote Java Application
    • Set the nameName: Maven
    • Keep all the existing settings and apply
    • Debug Remote Application

    • Select the Source tab and add source
      • File System Directory and browse to the Hibernate route source directory
      • Select the Search subfolders check box
      • Apply and close

      Add Source Folders

  • Use the Run > Debug Configurations menu to duplicate the Maven configuration for the Remote Java Application
    • Set the name
      • Name: Maven Debug
    • Change the port value
      • Port: 5005
    • Apply and close
    • Remote Application Maven Surefire Configuration

Set breakpoints and start the test

At least one breakpoint should be set in the source prior to the run configuration Surefire Debug is started

  • Browse the source tree in the package explorer to the test class
  • Set a breakpoint
  • Use the Run->Run Configurations menu and select the Maven->Surefire Debug configuration
    • Click debug to start maven
  • Eclipse breakpoint setting and starting maven from Ray Fan on Vimeo.

    Using Eclipse to browse the project source and set a breakpoint prior to starting maven to run the test.

    Start the debugger

  • Use the Debug->Debug Configurations menu and select the Maven Debug remote debugging configuration
    • Click debug to start the debugging session
    • Switch to the debugging perspective when prompted
    • Once execution of the test starts the breakpoint set previously should be hit
  • Starting to debug from Ray Fan on Vimeo.

    Starting to debug, switching perspective and hitting the breakpoint.

Related posts