Hibernate version: 2.1.2
Name and version of the database using: DB2 8.1 UDB
Hi,
Thsi question is a bit too long. Please bear with me. I appreciate your inputs.
I am currently looking into porting a J2EE application using Session EJB + Entity EJB (2.0) with TopLink to Session EJB + POJO with Hibernate.
With Hibernate, I will have to explicitly create Session in the begining and invoke Session.close() at the end of every transaction ( I use session per request model). That's easy.. However there is one small glitch for which I dont know how to approach.
Consider a Stateless Session EJB as follows:
public interface MySession extends EJBObject
{
public void method1()
public void method2()
}
Each of these methods are called independently by the client. In addition method2 also calls method1 during its execution. Hence I cannot put both session.open and session.close() in method1.
You might say hey... that is easy, create a method3 that invokes method1 and performs the session close. (Obtaining a session can be done by checking the ThreadLocal - as in the Caveatemptor example)
But, I have a constraint. The codebase I am porting also happens to be used for several earlier releases without Hibernate. Hence my strategy is to write a small code generation framework that will generate POJOs, and some POJO wrappers at build time from the Entity EJBs and use it with new Hibernate mapping files. This way I dont have to change any of the code containing business logic (which is continously changing).
As you can see, the code generation approach for the above scenario is going to be too complex. Instead I've been trying to go alternate route of getting my Stateless SessionEJB implement the SessionSynchronization interface. That way, I can implement the beforeCompletion() method to close the Session. I am no expert in JTA. Hence I wanted to know the opinion of experts in this forum about going down this route.
Thanks,
Srikanth
|