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

Generating Some Class

Our mapping contains information about both the database and the Java class between which it maps. We can use it to help us create both. Let’s look at the class first.

How do I do that?

The Hibernate Tools you installed in Chapter 1 included a tool that can write Java source matching the specifications in a mapping document, and an Ant task that makes it easy to invoke from within an Ant build file. Edit build.xml to add the portions shown in bold in Example 2-2.

Example 2-2. The Ant build file updated for code generation

<?xml version="1.0"?> <project name="Harnessing Hibernate 3 (Developer's Notebook Second Edition)" default="db" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant"> <!-- Set up properties containing important project directories --> <property name="source.root" value="src"/> <property name="class.root" value="classes"/> <property name="data.dir" value="data"/> <artifact:dependencies pathId="dependency.class.path"> <dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.7"/> <dependency groupId="org.hibernate" artifactId="hibernate" version="3.2.5.ga"> <exclusion groupId="javax.transaction" artifactId="jta"/> </dependency> <dependency groupId="org.hibernate" artifactId="hibernate-tools" version="3.2.0.beta9a"/> <dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec" version="1.1"/> <dependency groupId="log4j" artifactId="log4j" version="1.2.14"/> </artifact:dependencies> <!-- Set up the class path ...

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