Using Hibernate with Mule ESB – Part 1

If you are looking to use Hibernate with Mule ESB this is your place. Though Mule has a Hibernate transport, it is out date and it won’t work with Mule 3.
In this series we are going to explain different scenarios where you can integrate these technologies.

Let’s begin with something simple; suppose we are building an application that reads from a JMS queue and you would like to invoke a method in MyService Spring bean. Let’s assume we have the following Spring configuration:

and it’s implementation is as follows:

following our implementation you may try the following configuration for our scenario (assuming that the elements in the queue are long paramenters):

This implementation assumes that a Hibernate session exists for the current Thread; something typical in Web applications using the Open session in view pattern. Well in this case it won’t work because nobody has created a Hibernate session for you.

How to fix it?

There are several ways, in this case we are going to open the session and make the invocation transactional. To do so, first create 2 interceptors: a transaction interceptor and the hibernate interceptor.

Then you can refactor the Spring config as follows using the Spring’s ProxyFactoryBean:

Finally you will need to add a default constructor to be able to proxy your com.MyService class as follows:

Hope you like the post and stay tuned; we will present more alternatives to use Hibernate with Mule soon…


One Response to “Using Hibernate with Mule ESB – Part 1”

Leave a Reply