object-relational mappers in Java
After some time of absence to the Java, XML buzz world I had to reenter it lately for my master thesis. My current assignment is writing a data attraction and persistence layer. After finding out that there’s a multitude of possible frameworks and systems which I might use for my problem I dived right in, in contrary to BPEL engines most of them also worked.
The first step towards an advanced persistence solution was the usage of a ORM mapper. As the name implies those map between Java objects and relational data structures (i.e. databases). The programmer doesn’t see the underlying database world and just interacts with plain old Java objects. I started by using iBatis which occupies the one extreme of ORMs: the developer has to supply a SQL statement for each mapping. This also implies that the database schema is already defined before the ORMs is used. As I started from scratch I didn’t have a relational model, in fact I wanted to use an object-relational mapper to prevent myself from micro-designing the database layout.
The next contestant was Hibernate. This is one of the if not the most powerful object mapper for Java. In contrast to iBatis the latest version depends solely on Java annotations and a simple config file (which defines the overall database connection and declares which classes are to be mapped). I augmented my Java files and was ready to roll. After a bit of tweaking lazy loading also worked which isn’t to shabby for the invested time. Another advantage of Hibernate is HQL – the Hibernate Query Language: it provides the developer with an easy way of extracting Objects from databases through SQL-like queries.
But finally I settled with the Java Persistence API which is roughly the same as Hibernate but standardized through a JSR. There were minor differences with the annotations, but overall it was even simpler to use (the configuration file that stated which classes were to be persisted fell away). Under the hood I used Hibernate, but just through JPA, so performance and stability where the same.
The only drawback so far is the memory usage. JPA takes just all of it (and the JVM’s behaviour of starting memory reclaim as late as possible doesn’t help either). To ease this up I had to blurry the line between persistence and business layer a bit, this was felt as a step backwards as the goal was to minimize the persistence layer as much as possible.
As one of my thesis’ mentors prefers XML databases I will be able to contrast this to a XML based solution soon.
No related posts.