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


Partners & Affiliates











advertisement

Tutorials : XML-to-Database Mapping with Hibernate 3.1 :

XML-to-Database Mapping with Hibernate 3.1

by Deepak Vohra

Hibernate is an open source object/relational persistence and query service for Java. Hibernate's latest version, 3.x, introduces a new feature: XML-to-database mapping, which allows you to to map data representation in an XML document to a database (of which Hibernate supports several—including DB2, MySQL, Oracle, and PostgreSQL). With Hibernate, you map your XML document nodes to database columns. Only an XML mapping file is required to map an XML document to a database table; a POJO is not required. Hibernate generates the required SQL to create, update, and delete database tables. You can also use it togenerate tables from a Hibernate configuration file and add data to a database table from an XML document. You can retrieve database table data as an XML document and update it from that XML document. Further, Hibernate 3.x supports dom4j API for XML processing. Hibernate also provides classes for Ant build tasks. In this tutorial, you'll learn how to develop an XML/relational application with Hibernate 3.1.

The first thing you'll want to do is take a look at the database configuration properties, which are specified in the hibernate.properties file. These files specify the database, the JDBC driver class, and the connection URL you'll use to connect to the database. The mapping file, a hbm.xml file, specifies the XML document nodes and the corresponding database columns to which the nodes are mapped. The database table name to which a Java bean class is mapped to is also specified in the mapping file. You'll use the org.hibernate.tool.hbm2ddl.SchemaExport tool to map the mapping file to the database table. This tutorial will show you how to map an example mapping file (Catalog.hbm.xml), consisting of properties for a journal catalog, to an Oracle database table, OE.Catalog.

Preliminary Setup

You'll need the Hibernate API classes to develop a Hibernate application. Download Hibernate 3.1.2 and extract the files to an installation directory. Install the Oracle 10g database (to do so, install and create the database, refer to Oracle database documentation). Next, add the .jar files required to generate a Hibernate application to the CLASSPATH environment variable (the .jar files are listed in Table 1.

JAR/Zip  File

Description

<Hibernate3.1>/hibernate3.jar

The Hibernate API classes including the org.hibernate.tool.hbm2ddl.SchemaExport  class.

<Hibernate3.1>/lib/dom4j-1.6.1.jar, <Hibernate3.1>/lib/commons-logging-1.0.4.jar,  <Hibernate3.1>/lib/commons-collections-2.1.1.jar, <Hibernate3.1>/lib/ehcache-1.1.jar, <Hibernate3.1>/lib/cglib-2.1.3.jar, <Hibernate3.1>/lib/jta.jar, <Hibernate3.1>/lib/asm.jar, <Hibernate3.1>/lib/antlr-2.7.6rc1.jar

<Hibernate3.1>/lib/jaxen-1.1-beta-7.jar

 

The auxiliary Hibernate classes.

<Oracle10g>/jdbc/lib/classes12.jar or ojdbc14.jar

The Oracle   database JDBC classes.

 

Table 1. Hibernate JAR Files

Table 1 shows <Hibernate> as the directory, C:/Hibernate/hibernate-3.1, in which Hibernate 3.1 is installed.

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.

XML error: undefined entity at line 19
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%.

Linux Vendors Head to the Cloud in Search of Cash
iPhone 3GS: Overheating Fears, OS Update Nears
PostgreSQL 8.4 Revs Up Database Admin, Security
PHP 5.3 Accelerates PHP
Sun Releases NetBeans 6.7 IDE for Java, PHP
Why Firefox Doesn't Take Google Chrome Features
First Major PHP Update in Years Coming Soon
Red Hat CEO Calls on Oracle to Keep Java Open
Google Widens AdSense for iPhone, Android Apps
Eclipse Galileo Releases 33 Open Source Projects

A Taste of JavaFX for the Uninitiated
A Guide to Caching and Compression for High Performance Web Applications
How User-Centered Design Can Put User Stories in Proper Context
Explore C# 4's New Dynamic Types and Named/Optional Parameters
Enterprise Architecture: The Journey Begins Here, Part 2
Create a Syslog Sender/Receiver Using the MS Winsock Control
AMD CodeAnalyst Helps Developers Optimize and Tune Applications
Securing Microsoft's Cloud Infrastructure
Introducing the Azure Services Platform
An Introduction to Microsoft .NET Services for Developers

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs