Friday, May 26, 2006

 

Looking at Java™ EE 5 for useful features.

Coming from a background where we used an object-oriented database (ObjectStore in fact!), I'm always to keen to look at technologies that provide a layer of abstraction over any underlying relational database. I had been looking at the Java Data Objects specification with a view to this end. This is a specification that has run in parallel to Enterprise Java Beans. They come from different backgrounds and view points, but go about achieving roughly the same thing in similar ways(!). The JSR for Java™ EE 5 recently went final, so I've been looking at that too, what with it's Persistence API that can be run outside of the application server container. Unfortunately I think both are a bad fit for our purposes. Our event model is very simple and really should just map to a single class (or table in SQL speak!). The tutorials for these technologies I've mentioned always talk about mapping complex relationships, using sporting examples where you have teams, players and leagues. You can express the cardinalities of the relationships as things like OneToOne, OneToMany,

ManyToOne or ManyToMany via annotations on the appropriate attributes / properties. They also support the notion of cascading delete so that if a persisted object entirely relies on the existence of another, if the object on which it depends gets deleted, it will too. Again, you can express this easily through annotations. Alas, our data model is so simple we just don't need this kind of thing!

However, one thing that we could use is resource-injection. This is where you map something like a datasource to a JNDI name in the container and then refer to it from within your application. Instead of explicitly writing JNDI code to get a handle on this datasource, you can just mark up as associated variable with the annotation @Resource and the container will do the binding for you.

A library that we think will be applicable for our purposes is a library called Hyperjaxb2. In principle you can take the JAXB classes that you've generated from your XML schema (which we've already done). Then, in conjunction with Hibernate you can create an object-relational mapping, to bind your classes to a particular database. You can also use Hibernate to then generate the mapping for other database vendors. You can use Hibernate's own HQL query language in order to perform queries on the data and retrieve the results as XML going via the JAXB classes again. It'll be interesting to see if it works as desired (the only foreseeable drawback is that it's only at 0.4, but maybe the developers are ultra-conservative with their versioning!).


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?