Confussed about how to proceed: JNDI vs. Others for HA
I have been using Spring for a while, both in my personal projects and professionally. I was introduced to Spring and Hibernate some time ago while working on a rather large JBoss project. Because of the size of this project, we took the stand of splitting the functionality of the application as a whole into separate WAR files, glued together using JNDI.
Since we didn't use clustering at all, it was rather easy. And, since most of the parts of the application used a common data structure, we had a "common" Data Access deployment that registered a bunch of Hibernate DOAs (all extending HibernateDaoSupport) into our JNDI model. It worked very well, and I replicated this success multiple times throughout most of the projects I worked on.
Lately, however, I started working on a new pet project, and decided to migrate all my libraries over to Spring 2.5 and the latest Hibernate (3.2.2). Everything was going fine, that is until I tried to use one of my DAO objects I got from JNDI. At this point, both the SessionFactory and HibernateTemplate, two fairly important parts of the whole DAO infrastructure. The funny thing is, I am not really accessing the DAOs directly, but rather through a "Service Object" that is exported from Spring into JNDI.
From what I have gathered from my posts and those of others, Spring has changed some of its Hibernate Support classes, removing some of its ability to serialize objects that inherit from classes like HibernateDaoSupport. Again, I have not confirmed this in the Spring code directly, and my own experimentation has concluded on that I can get non-null SessionFactory and HibernateTemplate when the DAO is built by Spring, but null later. I also confirmed that, even though the member variables of my service object stay consistent, the object IS recreated when pulled out of JBoss JNDI. Its a lengthy off-topic discussion on how I did this, but lets say it was with some calls to System.getTimeMillis() and the object reference itself.
That said, I am at an impasse as to how to architect my way past this minor setback. My ultimate goal in this project was to use JBoss HA for load balancing and clustering. In my original schema I was going to create all the service layer with standard interfaces, register them all with JNDI, then give the control layer access to those service classes by handing them the JndiTemplate and the JNDI name for the object. This way, I could just point them all to the JNDI/HA and let JBoss do the work of routing where the requests go. I thought it was brilliant, but now I am lost.
I guess there are a few directions I could go. I could export it all as a web service, but then I have to eat the performance hit of web services. I could inject the service objects directly into the controller layer objects, but that doesn't give me the dynamic load balancing and fail over I was hoping to have. Then there are EJBs, which technically could be made to work in an HA setting with JBoss, but I have never had any personal experience with EJBs that would make me consider using them. I am sure there are some other options as well, but I just can't come up with anything feasible.
What are other people doing to solve this? Am I smoking the crack pipe here? I have to guess someone else is trying to get to the same requirements that I am.
I would love to hear what others are thinking...