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.

 BlackBerry Application Development Resources
 Microsoft Visual Studio 2010 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%.

ActiveState Debuts Open Source Business Suite
Salesforce Offers Visual App Builder
Codesion Steps Out From CVS's Shadow
Facebook Makes Major PHP Push With HipHop
Free Ride Over for Microsoft Azure Users
Drupal Opens the Garden to Boost CMS
Oracle Talks Plans for Linux, Solaris
Azure Makes Cloud Computing Innovation Safe
Red Hat's JBoss Looks Ahead
Microsoft Readies Two Windows Phone Systems?

Apple Surveying iPhone Developers? Happiness With The App Store
HTML 5 Leaves Client Storage Open to Web Attacks
Basic Market Forecasting with Encog Neural Networks
Location-Aware App Review
The Future of Web Content -- HTML5, Flash, and Mobile Apps
Moonlight 3.0 Preview Offered For Rich Internet Apps on Linux and Unix
Why a Moderator is Key in the Engineering Review Process, Part II
Windows 7 Features Your Clients Will Need on Day One
What Your Clients Will Ask About Windows 7
Melissa Data Helps Developers Improve the Quality of Business Data

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


The Network for Technology Professionals

Search:

About Internet.com

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