Call CJT now on +44 (0) 1273 722 544 or contact us
Friday 3rd, September 2010

A framework mashup

Posted by Jethro Grassie on November 16, 2008

Recently we have been working on another web app – or RIA as some would coin.
When we do server side stuff at CJT, we often make use of Java, J2EE more specifically.
This particular project required a flex front end.

On the server then, we do our usual hibernate for persistence and spring for the IoC which all yields a nice well designed and configurable server side web app.
What made this job a little more interesting was we wanted to have a play with one of Adobe’s recent open-source contributions – BlazeDS.

Among other things, BlazeDS gives us remoting, which is what we wanted for this particular project. We can call our remote Java services and pass actionscript objects to the server, these are serialized to and sent over as AMF. BlazeDS (the server-side J2EE web app), deserializes this AMF into Java objects. When returning objects to the client, BlazeDS serializes the Java object(s) and then the client side flex app, deserializes the AMF back into actionscript objects. Neat.

However, all good and well, what happens when you want to integrate BlazeDS into the rest of your J2EE infrastructure?
Luckily enough, BlazeDS does allow for the configuration to assign a factory class to deal with looking up your services. So we write a factory that returns Java beans (our service classes) we have configured via spring. BlazeDS calls the appropriate methods on the service bean passing in the deserialized AMF method parameters. The result is then serialized and sent back to the client flex app. Sweet.

One gotcha we faced was this…
As we are using hibernate for persistence, we could (and needed to) make use of lazy collections. That is, when a persistent object holds any kind of collection, hibernate can return empty proxy objects in the collection that only actually retrieve the value when the caller asks for it (eg iterating over the collection). This is a great way to reduce overhead, but Blaze’s implementation just doesn’t handle this out of the bag, so when returning a lazy collection, flex simply couldn’t retrieve the objects in that collection.
Now with large tree structures of data objects, we couldn’t simply switch off the lazy loading in our hibernate mappings to allow returning to flex the whole object tree, so we had to look to keeping it lazy. Not difficult, we just had to add in the necessary service calls for this projects data model.

In summary, we got BlazeDS, hibernate and spring all working together nicely, just would have been nice if BlazeDS handled lazy collections for us. They are commonly essential for an enterprise level application.
I would say, at the moment, the superb Granite Data Services is a better option at present over BlazeDS.
It handles all that BlazeDS does and more. It also deals with the lazy loading issue ;)

References

BlazeDS: http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/
Granite Data Services: http://www.graniteds.org/
Spring: http://www.springframework.org/
Hibernate: http://www.hibernate.org/
AMF specification [pdf].

2 Comments »

  1. BlazeDS and the art of lazy loading

    May 13, 2009 // 6:05 am

    [...] A while back I had some fun playing with Flex, Spring, BlazeDS and Hibernate. [...]

  2. blog.custom-widgets.co.uk | The Blog

    May 15, 2009 // 7:24 pm

    [...] upon a number of interesting posts related to this subject.  CJ Tech’s discussion of using Flex, Spring, BlazeDS and Hibernate and Actionscripter’s Papervision3D and Box2D Experiments were of particular interest due to [...]

Leave a Comment

Like what you see? Then get in touch;
t. +44 (0) 1273 722 544   e. contact us