Feeds

Hibernate Object Relational Mapping

First in a two-part series by Java guru John Hunt

  • alert
  • submit to reddit

The Power of One Brief: Top reasons to choose HP BladeSystem

How many Java applications have you built that store data in a database? For me, almost all the Java systems I have been involved with have, at some point, involved a database. In general, what has happened is that data held in objects, at some point has been stored into the database, so that it can be restored back into objects later. Thus, the database has acted as a persistent storage device for information required by the Java system. This can of course be achieved in a variety of ways, and the use of JDBC lies at the heart of this process.

However, mapping the Java (object oriented) world into the relational world of modern databases is not without its own set of issues. The object world and the relational world are two very different paradigms. The Object world deals with classes, instances of those classes and relationships between those instances. The relational world instead deals with tables, rows and the relationships between those tables. In the middle sits SQL, which is a declarative language used to specify a function that determines which columns and rows are returned at any one time.

While this may not be too much of an issue for a single object that can be easily mapped to a single table in the database, things get more complicated in the real world. If what you need to persist is a network of objects, which map to numerous tables (where there may or may not be an object-per-table mapping) this becomes much more complex and the amount of SQL you may need to write can very quickly grow.

Thus mapping between the two paradigms is not trivial and indeed to be successful at this you need to have a reasonable level of expertise in Java, SQL and database design. These skills are not only in demand, but are also hard to come by. An Object Relational Mapping tool (ORM) tries to alleviate this process by providing the means to automatically map form the object world into the relational world (and back again). It aims to make the database storage of objects (and even networks of objects) as simple as Java’s serialization.

Hibernate (available here) is an example of an ORM. It is probably the most widely used open source Object Relational Mapper currently available.

Hibernate

Hibernate is an Open Source Object Relational Mapper. Its aim is to remove the majority of the drudgery and time consuming repetitive coding needed for implementing your own Java-to-Relational mapping system. Thus, Hibernate handles the task of mapping classes to tables, and objects to actual rows. Hibernate generates SQL for you, relieves you from manual result set handling and object conversion and keeps your application portable to all SQL databases (no mean feet in itself).

In particular, Hibernate provides for transparent persistence (at least form the point of view of the object being persisted) - the only requirement for a persistent class is a no-argument constructor. Hibernate is one of the most mature and most complete open source object-relational mapping tools. It is widely used and very actively developed; it is also appearing in more and more systems including JBoss and is often combined with Spring. In the case of JBoss, Hibernate is a critical component of theJBoss Enterprise Middleware System (JEMS) suite of products.

Seven Steps to Software Security

More from The Register

next story
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Application security programs and practises
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Securing Web Applications Made Simple and Scalable
Learn how automated security testing can provide a simple and scalable way to protect your web applications.