EJB3 persistence with hibernate

Since my trip to java posting I looked into EJB3 persistence (JSR-220) with hibernate as promised. It’s shocking how much the EJB3 specification resembles hibernate – Gavin King apparently got most if his hibernate semantics in there. I believe it’s a good thing though. Former hibernate developers can adapt the new sepecification with little effort and on the other hand the definition of persitience classes has been cleaned up nicely with properly defined annotations.
So far I’ve been able to create a simple example application with the hibernate entitymanager/annotations engine. It simply creates two objects, stores them in the database an reads them again with a query. The rest of this post shows how this example app is set up.
Continue reading

A trip to java

Once again a long time has passed where I couldn’t find the time or motivation to write a post. I was mainly occupied with the specification of a java application which gave me the opportunity to get to know Sparx System’s Enterprise Architect. I only used the common uml diagram types and the code generation features for this project and they work pretty well. I’d love to make use of the more advanced features though and look into the whole MDA approach a bit more. There is a fundamental difference in just drawing some class diagrams and really developing model driven from the ground up. Projects like AndroMDA to generate complete applications look promising and certainly could reduce the expenses for software development but I doubt I’ll find time to check it out properly any time soon. As for the modelling language I don’t think everything should be done with UML though – the approach to model every aspect in UML and using stereotypes to define “what it means” makes the modeling too confusing and complex imho. Some interesting views on MDA and Software Factories can be found in the podcast MDA vs. Software Factories and some older episodes.

At the moment I’m working on a prototype for another java application and got used to the new java 1.5 features like generics and the new for each loops. The generics are definately the way to go for typesafe collections and I’ll try to use them from here on out. I found the wildcard <? extends> and some other constructions confusing at first but I do understand that there are several restrictions (german link) when using generics. Someone should publish some design patterns for typical cases that require generics.

For that project I also experimented with BeanShell which is basically a java scripting interpreter. I’ll probably use it for custom formulas which are evaluated dynamically within the java application. Easy to use and powerful.

The next component I’ll look into is EJB3 persistence using Hibernate. I have worked with the hibernate tools and reverse enginered some database tables but since I already have the POJO classes and don’t want to create all the old hibernate xml mapping files I might as well check out how to create EJB3 persistence by using annotations. More on that soon.