Hibernate 3 Adds XML-Relational Persistence

Hibernate 3 Adds XML-Relational Persistence

ibernate has taken the IT world by surprise with its easy-to-use, high-performance, and sophisticated features for object-relational (OR) persistence. The most recent version of Hibernate (version 3, released on March 29) brings an important new feature to the product API: XML persistence. With Hibernate 3, Java application developers can conveniently persist XML documents into relational databases.

This new feature definitely should appeal to existing Hibernate developers because it follows the same persistence methods as POJOs (plain old Java objects), requiring a minimal learning curve. The convenience of XML persistence should appeal to new users as well. This article describes the Hibernate 3 persistence method.

Why XML Persistence Is Important
Most of the larger commercial databases support some form of native XML persistence. Since XML persistence is a relatively new mechanism?even for larger vendors, the standards in this field are still emerging. As a result, in order to integrate the ubiquitous relational persistence mechanisms with increasingly prevalent XML solutions, an architect must either resort to vendor-specific features or implement a custom XML persistence framework. Neither is a particularly attractive option. Vendor-specific features are unpopular because they can lead to vendor lock-in, and a custom framework implementation can be laborious and lengthy, resulting in code that is hard to maintain.

As is the case with OR persistence, Hibernate XML persistence is as a natural solution for this scenario. It is portable across all of the relational platforms that Hibernate supports (i.e., virtually all true relational platforms), allowing for the freedom to migrate objects and XML-based application and integration solutions without worrying about the underlying relational implementation.

Architectural Specifics
Hibernate is a nicely architected framework that seamlessly utilizes native environments without any special interventions or installations by the user. Switching from one database to another is usually a matter of changing a driver and configuring Hibernate (one-line configuration setting) to use one database dialect versus another.

Hibernate utilizes the dom4j framework for XML parsing and manipulation. To fully utilize Hibernate’s XML features, you must get familiar with dom4j. Most likely, you will find dom4j easier to use than JAXP and JAXP-compliant XML parsers that are supplied through Java. It has a very flat learning curve and you can start using the Hibernate XML persistence features effectively with minimal dom4j knowledge.

A Real World Example: Price Catalog Synchronization
A common e-business scenario should demonstrate the usefulness of XML-relational persistence mechanisms. Consider an example in which XML integrates priced product catalogs between online merchants and vendors.

The electronic catalog contains the priced product lists. The online store sells the products, which it manages through its own inventory (similar to Amazon’s relationship with Toys-R-Us and sporting goods stores). In order to accurately and efficiently reflect price updates, the online merchant needs to receive frequent product pricing feeds. It receives these feeds as an XML document that looks similar to this:

	"3" sku="100101">	         		Athlete mode body fat scale		100.00		60.00			"4" sku="100102">		Thermometer		20.00		11.00	

The comprehensive master product price list is stored on the database as follows:

CREATE TABLE PRODUCT(  id INT UNIQUE NOT NULL,  description VARCHAR(45) NOT NULL,  sku VARCHAR(45) UNIQUE NOT NULL,  list_price FLOAT,  base_price FLOAT,  order_price FLOAT,  CONSTRAINT PK_PRODUCT PRIMARY KEY (id ))

The online store presents a Web representation of the priced catalog through the existing OR mapping, where the priced products are represented as demo.Product Java objects:

/** Product object represents the priced catalog item. */public class Product {		int id;	String sku;	String description;	Double listPrice;	Double basePrice;	Double orderPrice;

These objects also are mapped as the following (the column names are listed for clarity, even though Hibernate can auto-map the properties to column names if they match):

"1.0"?>"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">"demo">"Product" 	table="product"	node="product">	"id" 		type="int"		node="@prod_id"		column="id">		"sku" node="@sku" column="sku" not-null="true"/>	"description" node="description" column="description"  not-null="true"/>		"listPrice" node="list_price" column="list_price" />	"basePrice"  node="drop_price" column="base_price"/>	"orderPrice" column="order_price"/>

In this scenario, Hibernate’s XML-relational persistence comes in very handy. As the e-business application receives XML feeds containing the product price updates, it persists them into the product database utilizing Hibernate’s XML persistence mechanisms. Hibernate offers several XML persistence alternatives, including the Hibernate saveOrUpdate method:

		document = saxReader.read(inputXML);		List users = document.selectNodes("//product");		try {			Session session = HibernateUtil.sessionFactory.openSession();			Transaction transaction = session.beginTransaction();			Session dom4jSession = session.openSession(EntityMode.DOM4J);			Iterator iter = users.iterator();			while (iter.hasNext()) {				Object next = iter.next();				dom4jSession.saveOrUpdate("demo.Product", next );			}// end while			transaction.commit();			session.close();

XML Mapping Syntax
The mapping file that the previous example used is different from the Hibernate 2 mapping file. Hibernate 3 introduced several new mapping types specific to XML persistence.

The central new mapping attribute is a node, which relates either to the element within an XML document or to the attributes in the document that are to be mapped.

A “node” can represent a mapping of the following:

  • "element-name": In the case study, this would be expressed as a node=”product” for a element.
  • "@attribute-name": In the example, node=”@sku” would map to an XML attribute .
  • Period ("."): This maps to the parent of the element (like as a parent of the ).
  • "element-name/@attribute-name": These map to the attribute of the named element (product/@sku).

XML Persistence Not Hibernate’s Main Mission
Release 3 of the Hibernate framework effectively closes the cycle on the most common persistence methods available today (excluding only LDAP). Java community now has a framework that provides an efficient and consistent method for effortless OR and XML persistence.

With that in mind, understanding the Hibernate project’s mission is important. Even though the Hibernate 3 XML features are highly useful and attractive, they are not meant to replace the most popular XML marshalling or transformation frameworks. Despite a very comprehensive OR mapping solution, Hibernate is not expected to grow into a major XML manipulation framework (per Hibernate author Gavin King, TheServerSide Java Symposium 2005).

For that reason, you should take the XML persistence features as helpful extensions to the already powerful Hibernate framework, which enable you to easily incorporate another contemporary data representation mechanism into your application. If you have to deal with intricate integration and transformation scenarios, however, look into XML-specific frameworks.

devx-admin

devx-admin

Share the Post:
Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI

US Commitment

US Approves Sustainable Battery Research

The US Department of Energy has revealed a $325 million commitment in the research of innovative battery types, designed to enable solar and wind power

Netanyahu Musk AI

Netanyahu and Musk Discuss AI Future

On September 22, 2023, Israeli Prime Minister Benjamin Netanyahu met with entrepreneur Elon Musk in San Francisco prior to attending the United Nations. In a

Chinese 5G Limitation

Germany Considers Limiting Chinese 5G Tech

A recent report has put forth the possibility that Germany’s Federal Ministry of the Interior and Community may consider limiting the use of Chinese 5G technology by local network providers

Modern Warfare

The Barak Tank is Transforming Modern Warfare

The Barak tank is a groundbreaking addition to the Israeli Defense Forces’ arsenal, significantly enhancing their combat capabilities. This AI-powered military vehicle is expected to transform the way modern warfare

AI Cheating Growth

AI Plagiarism Challenges Shake Academic Integrity

As generative AI technologies like ChatGPT become increasingly prevalent among students and raise concerns about widespread cheating, prominent universities have halted their use of AI detection software, such as Turnitin’s

US Commitment

US Approves Sustainable Battery Research

The US Department of Energy has revealed a $325 million commitment in the research of innovative battery types, designed to enable solar and wind power as continuous, 24-hour energy sources.

Netanyahu Musk AI

Netanyahu and Musk Discuss AI Future

On September 22, 2023, Israeli Prime Minister Benjamin Netanyahu met with entrepreneur Elon Musk in San Francisco prior to attending the United Nations. In a live-streamed discussion, Netanyahu lauded Musk

Urban Gardening

Creating Thriving Cities Through Urban Gardening

The rising popularity of urban gardening is receiving increased recognition for its numerous advantages, as demonstrated in a recent study featured in the Environmental Research Letters journal. Carried out by

What You Need to Know About Cloud Security Strategies

What You Need to Know About Cloud Security Strategies

Today, many businesses are adopting cloud computing services. As a result, it’s important to recognize that security measures for data in the cloud are different from those in traditional on-premises

Romanian Energy Security

Eastern Europe is Achieving Energy Security

Canada and Romania have solidified their commitment to energy security and independence from Russian energy exports by signing a $3-billion export development agreement. The deal is centered on constructing two

Seamless Integration

Unlocking Seamless Smart Home Integration

The vision of an intelligently organized and interconnected smart home that conserves time, energy, and resources has long been desired by many homeowners. However, this aspiration has often been hindered

New Algorithm

MicroAlgo’s Groundbreaking Algorithm

MicroAlgo Inc. has revealed the creation of a knowledge-augmented backtracking search algorithm, developed through extensive research in evolutionary computational techniques. The algorithm is designed to boost problem-solving effectiveness, precision, and

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.

Sitemap