Feeds

Hibernate Object Relational Mapping

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

  • alert
  • submit to reddit

The essential guide to IT transformation

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.

Secure remote control for conventional and virtual desktops

More from The Register

next story
Apple promises to lift Curse of the Drained iPhone 5 Battery
Have you tried turning it off and...? Never mind, here's a replacement
China: You, Microsoft. Office-Windows 'compatibility'. You have 20 days to explain
Told to cough up more details as antitrust probe goes deeper
BBC: We're going to slip CODING into kids' TV
Pureed-carrot-in-ice cream C++ surprise
Linux turns 23 and Linus Torvalds celebrates as only he can
No, not with swearing, but by controlling the release cycle
Scratched PC-dispatch patch patched, hatched in batch rematch
Windows security update fixed after triggering blue screens (and screams) of death
This is how I set about making a fortune with my own startup
Would you leave your well-paid job to chase your dream?
prev story

Whitepapers

Endpoint data privacy in the cloud is easier than you think
Innovations in encryption and storage resolve issues of data privacy and key requirements for companies to look for in a solution.
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.
Advanced data protection for your virtualized environments
Find a natural fit for optimizing protection for the often resource-constrained data protection process found in virtual environments.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Next gen security for virtualised datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.