Sam Newman's site, a Consultant at ThoughtWorks

Archive for ‘November, 2003’

I hope to get a rough performance comparison of an enterprise application using entity beans for persistance compared to using Hibernate soon, in the meantime I thought that a brief comparison of the development effort involved in using the two approaches might be in order. Comparisons are based on JBoss 3.2.2 running MySQL.
Continue reading…

I decided to spend my Sunday afternoon giving “Seraph”: a go. Seraph is “Atlassian’s”: opensource web application securty framework. Upon downloading I found that it depends on “OpenSymphony’s”: (website tagline: “Quality Components”) “OSCore”:, and “OSUser”:, nether of which it includes in its downloads (despite the fact that specific version numbers are mentioned in the “dependencies”: No problem I think, I’ll just pop over to OpenSymphony to grab the latest OSCore and OSUser jars. Unfotunately you can’t. No download links, nothing. I eventually find in the OpenSymphony Wiki that the only way to actually get them is via CVS (and I only found this page via a Google search). Already I’m a little concerned – Seraph seems to be at a relatively early stage of development and is dependant on two apparently immature libraries (if all you provide is a CVS source download, you aren’t what I would call ready for prime time). Having already spent a little time at this I thought I should go one step further, so I fire up SmartCVS and download the repositories. Both OSUser and OSCore build easily enough, and not knowing much about either I decide I should look for some documentaion. OSUser contains little – the online API docs are broken, there does’t appear to be any docs in CVS, and the example app doesn’t build, and there is nothing like a quickstart guide (which was so helpful with Hibernate) so I have no way of knowing how the bloody things works.

Anyway trusting that the versions of OSUser and OSCore in CVS will work with Seraph, I’ll spend a little longer seeing if its worth going any further with it. I don’t hold out much hope…

Well, I managed to get “JBoss”: and “MySQL”: working thanks to a kind friend who dug his config files out. Getting “Hibernate”: and JBoss working together was fairly simple, although I hate the fact that the Hibernate libraries have to be stuck in JBoss’s own lib directory thanks to one of its infamous class loader problems that never seem to get fixed. A minor hiccup was when JBoss forced the MySQL driver into an auto commit mode which it doesn’t support (this is despite MySQL’s own driver defaulting to false), although passing in a parameter to the JDBC URL fixed that.

Throughout the whole process I’ve found Hibernate very user friendly – the error messages are informative and helpful, which is more than can be said for JBoss and Tomcat. Next up I’m going to create a sample object model with some one to many relationships with both Hibernate and as Entity beans, to get a rough idea of performance.

“Hibernate”:, as you may or may not be aware is a persistence engine for Java. As such it is by no means unique – it joins the ranks of JDO, Java Serialisation and the persistence features of the EJB specification as another option in an already crowded market. Good overviews on Hibernate can be found at the “official site(Hibernate and Tomcat Quickstart)”: and in an article over at “The ServerSide(The ServerSide – Introduction To Hibernate)”:

I like several things about Hibernate. Firstly it seems a lot quicker to develop than EJBs are.The classes you want to persist don’t need stub classes, or special interfaces – they are just normal beans. So not only can you quickly create these classes using code generation tools already in most modern Ode’s, but the beans themselves are abstracted from the method of persistence being used. Hibernate even ships with a tool to generate these classes from your mapping files, which is handy when used as part of an Ant build. Next, the definition of relationships is fairly easy – as is implementing lazy loading. The fact that you have to keep a Hibernate session if you want to use lazy loading of relationships is a pain but understandable.

The mapping files (which define the relationships between beans to be persisted and the datasource) is very straightforward, and as another nice touch Hibernate can read your mapping files and automatically create and keep in sync the database tables – again a great feature as part of a development build and deployment.

The reduced development overhead compared to EJB development coupled with the apparent performance improvements over simple untuned EJB applications means that I may find myself using this more and more. This weekend I’ll try and get a Hibernate-JBoss install working to carry out some simple performance comparisons between an EJB-based persistence and Hibernate based persistence.

Finally, after much cursing, shouting, drinking and general annoyance, I have managed to deploy a sample “Hibernate”: application. I must point out here that the problems I had have nothing to do with Hibernate – the documentation is excellent, although their sample application could be packaged a little better (you know, to actually produce a WAR file). The problem I had was with “Tomcat”:

Up to this point I have been using “Jetty”:, because it just WORKS. It doesn’t have fancy web-based admin consoles or more config files than you cna shake a stick at, you just put your WAR file in its webapps directory, and restart. At which point it deploys your webapp. Tomcat however doesn’t do that – oh no. Sometimes it ignores your WAR file. Othertimes it unpacks it, but if it does it won’t update this unpacked directory structure if the WAR file changes even if you restart Tomcat. So now my build process has to delete directory structures under Tomcat (I’m sorry, but I am not going to start dealing with unpacked WAR structures – that way madness lies). Oh, and guess what? When Tomcat has an error with a web.xml, it doesn’t tell you which webapp it found the file in! Isn’t that cool! “Now if Jetty was so good, why are you using Tomcat?” you may ask Well, this may be lazyness on my part but the example application had the tomcat config settings and I didn’t feel like working out the equivelent Jetty settings (why can’t these things be standardised?).

Up to then things had gone well – I got “MySQL”: installed and running as a service quite quickly. After finally getting the Hibernate example working I had a quick look at getting Hibernate and JBoss working together, but hit the problem that I couldn’t find any documentation explaining how to get “JBoss”: working with MySQL – that excersie can wait for another day. Anyway, expect a brief writeup on Hibernate tomorrow – I must say that from what I’ve seen already it looks excellent.