advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Reviews : Java Books : Hibernate: A Developer's Notebook :

Buy this book
Title: Hibernate: A Developer's Notebook
ISBN: 0596006969
US Price: $16.97
©2004 O'Reilly

What just happened?

We took the abstract description of the information about music tracks that we wanted to represent in our Java code and database, and turned it into a rigorous specification in the format that Hibernate can read. Hopefully you'll agree that it's a pretty compact and readable representation of the information. Next we'll look at what Hibernate can actually do with it.

What about...

. . . Other data types, including nested classes and enumerations? Relationships between tables? Indices? Class hierarchies and polymorphism? Tables that contain rows we need to ignore? Hibernate can handle all these things, and we'll cover most of them in later examples. Appendix A lists the basic types that Hibernate supports "out of the box."

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 Extensions 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

1    <project name="Harnessing Hibernate: The Developer's Notebook" 
2    
3             default="db" basedir=".">
4      <!-- Set up properties containing important project directories -->
5      <property name="source.root" value="src"/>
6      <property name="class.root" value="classes"/>
7      <property name="lib.dir" value="lib"/>
8      <property name="data.dir" value="data"/>
9    
10     <!-- Set up the class path for compilation and execution -->
11     <path id="project.class.path">
12         <!-- Include our own classes, of course -->
13         <pathelement location="${class.root}" />
14         <!-- Include jars in the project library directory -->
15         <fileset dir="${lib.dir}">
16           <include name="*.jar"/>
17         </fileset>
18     </path>
19   
20     <target name="db" description="Runs HSQLDB database management UI
21   against the database file--use when application is not running">
22         <java classname="org.hsqldb.util.DatabaseManager"
23               fork="yes">
24            <classpath refid="project.class.path"/>
25            <arg value="-driver"/>
26            <arg value="org.hsqldb.jdbcDriver"/>
27            <arg value="-url"/>
28            <arg value="jdbc:hsqldb:${data.dir}/music"/>
29            <arg value="-user"/>
30            <arg value="sa"/>
31         </java>
32     </target>
33   
34     <!— Teach Ant how to use Hibernate's code generation tool —>
35     <taskdef name="hbm2java"
36              classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
37              classpathref="project.class.path"/>
38   
39     <!— Generate the java code for all mapping files in our source tree —>
40     <target name="codegen"
41             description="Generate Java source from the O/R mapping files">
42       <hbm2java output="${source.root}">
43         <fileset dir="${source.root}">
44           <include name="**/*.hbm.xml"/>
45         </fileset>
46       </hbm2java>
47     </target>
48   
49   </project>

We added a taskdef (task definition) and a new target to the build file. The task definition at line 33 teaches Ant a new trick: it tells Ant how to use the hbm2java tool that is part of the Hibernate Extensions, with the help of a class provided for this purpose. Note that it also specifies the class path to be used when invoking this tool, using the project.class.path definition found earlier in the file.

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Microsoft Visual Studio 2010 Showcase
 Avaya Developer Showcase
 MSDN Spotlight
 PHP for Windows Showcase
XML error: undefined entity at line 39
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Windows 7: From Beta to Final Code in One Year
Google Shows Off Chrome OS, Releases Source
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?
Fedora 12 Takes Aim at Linux Networking
Top Supercomputer Nearly Doubles in Speed
Fedora 12 Linux Tackles Virtualization
Apple Gives iPhone Developers App Status Tracker
Novell Sets OpenSUSE 11.2 Free

Creating Custom Export Filters for StarOffice with XSLT
WPF Wonders: Using DataTemplates
Crystal Reports Family Offers Options for Developers
Avaya Aura Session Manager video
Avaya Aura Overview video
Exploring HTML 5's Audio/Video Multimedia Support
Overriding Virtual Functions? Use C++0x Attributes to Avoid Bugs.
Understanding the Cloud Computing Security Vulnerabilities
Cisco and IBM Target a Greener World
Upgrade to Visual Studio 2010 with the Ultimate Offer

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs