Call Encore now on +44 (0) 1273 722 544 or contact us
Sunday 7th, February 2016

BlazeDS and the art of lazy loading

Posted by Jethro Grassie on May 13, 2009

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

We recently won a contract to create quite a large on and offline application that we are implementing the GUI in Flex and the back-end in J2EE.
Given how much we like Spring and Hibernate, and how useful BlazeDS is, I have spent a bit of time again getting these all playing nicely together.

Firstly there is now a Spring and BlazeDS integration kit available which moves the configuration of BlazeDS completely to Spring. I really wanted this in our latest setup as it is far more elegant than the mish-mash of configuration files before.

Secondly there are now a couple of lazy loading frameworks for BlazeDS and Hibernate. We identified Gilead and dpHibernate as contenders. We really wanted decent automatic lazy loading for this particular project due to the size of the data model. Lazy loading is critical in any Flex-BlazeDS web app that is going to have a large and deep data model, otherwise the whole data model will have to go over the wire when only little bits of it are actually needed.

Getting this all working together nicely was not however straight forward!

Firstly I spent some time evaluating Gilead. At the time of writing, this simply doesn’t do what it says on the tin.
I was expecting automatic lazy loading but Gilead does not do this. Rather, it expects you to make the calls and what it does offer is the merging and cloning of objects. This solution is not a complete lazy loading solution and still would require quite a lot of code around it to achieve automatic lazy loading. So I moved onto dpHibernate…

And this gladly does do what one would expect! The source code is also very nicely written and well laid out, which made a thorough examination quite easy.

Next up was getting the Spring and Flex integration kit setup.
This went fine until trying to configure in dpHibernate, as the M2 release (which was current release at the time), didnt have support for wiring in and configuring a custom BlazeDS adapter, essential for any lazy loading solution.
Luckily, in the trunk was work by the very talented Jeremy Grelle which seemed to be the solution.
Getting it to actually work took a bit of debugging but I finally got there and documented the core stumbling block here.

So what we end up with is a Spring configured BlazeDS web app with a Hibernate persistence layer with lazy collection loading.

As I final point I want to highlight the issue of LiveCycle Data Services, which is Adobe’s commercial offering of BlazeDS, and does handle lazy loading out of the box.
My problem here was that after 6, yes SIX, attempts to get a cost from Adobe for LiveCycle DS, Adobe failed to ever respond (I tried all the contact options detailed on the product page).
Apart from lazy loading, the other reason we quite liked the idea of LiveCycle DS was the on/off-line data synchronization it has for AIR applications (as we will also be creating an AIR app for this particular project). Instead we will roll are own framework for this bit, and likely open-source it. So Adobe, if your listening, you lost a sale here by simply not responding. I wonder how many other potential sales have been missed?


  1. Bruno Marchesson

    May 13, 2009 // 5:06 pm


    As Gilead author, I would like to add some comments : automatic lazy loading is indeed not implemented in my library, but it is a choice.
    From my Hibernate experience, lazy loading generally leads to poor performances *on server* when not used properly, because of N+1 select and cartesian product among others…
    So adding remote call upon this looks to me a *very* bad idea !

    As a side note, I would like to insist about that Gilead *does* work with Flex, and is used by many developers, on professional applications. It just works differently from dpHibernate.

    Best Regards

  2. Jethro Grassie

    May 13, 2009 // 5:47 pm

    I have nothing against Gilead, it just doesn’t do what its promoted as doing.
    I am not saying it doesn’t work with flex, just that it doesn’t do lazy loading.

    You seem to promote it on every thread that discusses lazy loading, which it just doesn’t solve on its own, the developer still need to write specific service calls to enable the proxy objects to be filled in with the real objects on a per collection basis.
    This is what we did on our last BlazeDS based app, and it was fine for that as the model was way smaller than this current job (which will take considerable time to write all the service classes if we used Gilead.

    Also, regarding your comment on performance of lazy loading and hibernate, in my experience, its very important you configure which collections and objects you are going to load lazily or not in the mapping files (or annotations if thats your bag) and this is based on your particular model and domain. This way, you can decide where it makes sense to lazy load or not. dpHibernate doesn’t force you to lazy load everything, it just works based on what is setup in hibernate.

  3. Michael Labriola

    May 15, 2009 // 9:56 pm

    Good article, thanks for writing up this information for others.


  4. Ryan

    June 22, 2009 // 1:35 am

    Thank you, this saved me some time!

  5. Daniel

    July 27, 2009 // 1:31 am

    I’ve been looking for the information that’s been covered in this article for a little over a day now, thanks!

  6. Jgeek

    November 30, 2009 // 4:45 am

    Why do you have to use dpHibernate or Gliead?

  7. Jethro Grassie

    December 2, 2009 // 12:39 pm

    @Jgeek you dont if you dont want lazy collection loading

  8. Jochen

    February 16, 2010 // 7:11 pm

    Excellent Article Jethro. Thank you very much. I have forwarded this to some people at Adobe. They should be getting in touch, even though I know this is way too late for your project now.

  9. Simon Widjaja

    February 23, 2010 // 2:52 pm

    Hi! Nice article. We had the same experience with the adobe support team regarding the LCDS information. We dropped several requests some months ago and didn’t get feedback ’till now. Did you guys finally get in touch with the right contact persons? I really like the model driven approach and the LCDS features, but I don’t really get Adobe’s communication strategy and pricing modell around this product. What are your opinions and experiences?

  10. snk

    August 6, 2010 // 9:51 am

    Excellent Article,So what is the way to achieve lazy loading in plain pure JPA?Any ideas?

Leave a Comment

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