O'Reilly logo

Harnessing Hibernate by James Elliott, Ryan Fowler, Timothy M. O'Brien

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Code Generation

Let’s take a look at how we would replicate the codegen Ant target we created back in Chapter 2. To avoid sending you off on a page-flipping side trip, that target is reproduced as Example 11-1 here.

Example 11-1. Our code generation Ant task revisited

  <!-- Generate the java code for all mapping files in our source tree -->
  <target name="codegen" depends="usertypes"
          description="Generate Java source from the O/R mapping files">
    <hibernatetool destdir="${source.root}">
      <configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
      <hbm2java jdk5="true"/>
    </hibernatetool>
  </target>

To reconstruct this within Eclipse, we started by choosing Open Hibernate Code Generation Dialog from the menu shown in Figure 11-32. The window that appears (Figure 11-33), like many of the Eclipse tools, provides a way of setting up a variety of named configurations you can run.

Preparing to create a new Hibernate code generation configuration

Figure 11-33. Preparing to create a new Hibernate code generation configuration

Tip

You seem to need to click on the Hibernate Code Generation label before the “New” button becomes active to create a new configuration.

Once we figured out how to activate it, we clicked on the “New” button (the one that looks like a little page with a plus sign at the top right corner) to set up a configuration to generate our data objects. That opens a configuration window with many options, some of which you can see in Figure 11-34 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required