Feeds

Hibernate Object Relational Mapping

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

  • alert
  • submit to reddit

Intelligent flash storage arrays

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.

Internet Security Threat Report 2014

More from The Register

next story
Be real, Apple: In-app goodie grab games AREN'T FREE – EU
Cupertino stands down after Euro legal threats
Download alert: Nearly ALL top 100 Android, iOS paid apps hacked
Attack of the Clones? Yeah, but much, much scarier – report
You stupid BRICK! PCs running Avast AV can't handle Windows fixes
Fix issued, fingers pointed, forums in flames
Microsoft: Your Linux Docker containers are now OURS to command
New tool lets admins wrangle Linux apps from Windows
Facebook, working on Facebook at Work, works on Facebook. At Work
You don't want your cat or drunk pics at the office
Soz, web devs: Google snatches its Wallet off the table
Killing off web service in 3 months... but app-happy bonkers are fine
First in line to order a Nexus 6? AT&T has a BRICK for you
Black Screen of Death plagues early Google-mobe batch
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
10 threats to successful enterprise endpoint backup
10 threats to a successful backup including issues with BYOD, slow backups and ineffective security.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Beginner's guide to SSL certificates
De-mystify the technology involved and give you the information you need to make the best decision when considering your online security options.