SQL Zone is brought to you in partnership with:

Ouertani Slim was born in Tunisia in 1981. Now he is a software engineer since 2004 and he is Java 6 and Spring certified with 100% and 94% respectively. He is very interested in Java technology, Scala and open source projects. He believes that programming is one of the hardest jobs and most beautiful in the world. Slim has posted 32 posts at DZone. You can read more from them at their website. View Full User Profile

JBoss MQ and Hibernate Lazy Loading

  • submit to reddit

Today I will present a recent problem which I have faced in enterprise applications with an architecture that is based on DMZ and communications between backend and frontend using JBoss messaging.

In the integration step, I used the Hudson integration tool to get binaries. For this utility, I get one war file to be deployed in JBoss 4.2.3 GA and a second jar. The backend ( second jar ) communicates with the database using the Hibernate persistence provider and shares two JMS queues with the frontend. These binaries worked correctly on a developer machine but it's not the case in my laptop.

Investigations :

With no explicit exceptions, I start by debugging the frontend. To debug JBoss start it in debug mode:

export JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,adress=8888"

Next start JBoss and attach a debug socket using Netbeans facilities. With suspend=y, we can debug the init servlet method. if there are no errors there, set the flag to suspend=n. After some steps, I fixed the source of my problem


The backend requests the databse using Hibernate with lazy loading mode for collections. When the entity is serialized to be sent in the JMS queue, the frontend will try the get message from queue and cast it to appropriate entity class as sent by the backend. But this cast has failed. Why?

In fact, the backend comes with it's own version of Hibernate and my JBoss server has it's embedded Hibernate jars. Lazy loading in Hibernate collections means creation of proxy collection object to be filled if we try to get it inside a session, otherwise we get an exception.

The problem is due to static final long serialVersionUID  which is different in two proxy collections. The frontend can't read that entity because it doesn't have the same class identity as sent by the backend.


As a first solution, I used the same Hibernate lib for the backend and it worked fine. But serious attention should be taken to avoid sending proxy through a network if we can't be granted to have the same libraries. if I had used another JEE server, such as Glassfish, I don't encounter these problems as I use EclipseLink by default and I will deploy the same backend library.

Otherwise should we use value objects with entities to avoid theses problems?
Published at DZone with permission of its author, Slim Ouertani.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Mladen Girazovski replied on Wed, 2009/10/28 - 6:41am

These binaries worked correctly on a developer machine but it's not the case in my laptop.

 Sounds like you're missing an integtrationtests on your CI Server (Hudson), did the developer edit his JBoss installation manually? ;)

You can use the Cargo framework for installing, configuriering, starting   & deploying to an AppServer like JBoss, works from Maven2 or Ant.

In any case, the frontend should use identical library versions in the frontend & backend, otherwise you facing a big unknown risk (Does the version x.y work with version a.z???). Again, Maven2 can help here a lot.

 Of course, if you use eclipseLink, then there are no proxies and this Problem (and others) will dissapear.


Slim Ouertani replied on Sat, 2009/10/31 - 2:36pm in response to: Mladen Girazovski

Thanks mgira,

Of course we are missing an integration tests on our process. the developer tricks take one day for me to detect this problem. As he always said the magic word : " it works for me" :)


Here integration test are a must.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.