magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Posts from the ‘Development’ category

Well, it finally seems to be coming together. I have a build that creates a very simple webapp (can create 1 single object type) using “Hibernate”:http://www.hibernate.org for persistence, “XDoclet”:http://xdoclet.sourceforge.net/ to generate Hibernate mappings, and “Spring”:http://www.springframework.org/ to pull it all together. The build is quite frankly a mess (its an amalgamation of about 3 example build scripts with my own hacks thrown in for good measure). I’m going to get the build tidied up a bit, then on to the next challenges – integrating Session beans, web-services, and of course documenting the whole thing. It seems I’m a glutton for punishment…

Jean Tillman’s “article(Digital Web – User Interface Design for Web Applications)”:http://www.digital-web.com/features/feature_2003-11.shtml over at Digital Web Magazine outlines some of the differences between designing web sites and designing interfaces for web applications. Its well worth a read for anyone who develops web applications.

As a result of my research into “Hibernate”:http://www.hibernate.org that I’ve been doing over the last couple of weeks, I can across enough references to the “Spring Framework”:http://www.springframework.org/ for me finally to give it a look. I was quickly hit by the wealth of information out there, however nothing really provides a good concise overview – the Spring Framework “tutorial”:http://www.springframework.org/ for example is a 48 page PDF which gives an overview of each package in turn – not my idea of a tutorial at all. There seems to be an inordinate amount of waffle on the subject – looking at the petclinic example in the distribution, I can understand some of Spring’s power, but at the same time it can be very confusing. I’m fairly sure I can come up with a more concise getting started guide, which I’m going to aim to do over the next week or so.

Thanks to “kdub(kdub’s log)”:http://www.jroller.com/page/kwiersma/20030519#hibernate_xdoclet_tutorial, I spotted Mark Eagle’s tutorial on using “XDoclet and Hibernate(Object to Relational Mapping and Relationships with Hibernate)”:http://www.meagle.com:8080/hibernate.jsp (warning: seems to be running of someones app server on port 8080 – I’m grabbing a copy in case it vanishes). If it works as advertised then it could really speed up development time for me. Rather than generating the JavaBean from the mapping files, it generates the mapping file from the JavaBean sources. I’ll let you know how well it works…

_Updated 9:35am_: As feared, the site hosting Mark’s tutorial has gone AWOL. I’ll attempt to contact him to see if he wants me to host it for him…

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”:http://opensource.atlassian.com/seraph/ a go. Seraph is “Atlassian’s”:http://www.atlassian.com/ opensource web application securty framework. Upon downloading I found that it depends on “OpenSymphony’s”:http://www.opensymphony.com/ (website tagline: “Quality Components”) “OSCore”:http://www.opensymphony.com/oscore/, and “OSUser”:http://www.opensymphony.com/osuser/, nether of which it includes in its downloads (despite the fact that specific version numbers are mentioned in the “dependencies”:http://opensource.atlassian.com/seraph/dependencies.html). 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”:http://www.jboss.org/ and “MySQL”:http://www.mysql.org/ working thanks to a kind friend who dug his config files out. Getting “Hibernate”:http://www.hibernate.org/ 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”:http://www.hibernate.org/, 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)”:http://www.hibernate.org/hib_docs/examples/quickstart/html/quickstart.html and in an article over at “The ServerSide(The ServerSide – Introduction To Hibernate)”:http://www.theserverside.com/resources/article.jsp?l=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.