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.

 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