views:

1389

answers:

3

I'm using Websphere Application Server Express v6.1 and am writing an application which uses Spring 2.0.7, Hibernate 3.5. My datasource is Oracle 10g.

I have 2 question

  1. Which is a better transaction manager? Websphere's or Hibernate's?
  2. If IBM is the answer then how should I configure it in the spring config XML?

This is my current declaration for Hibernate

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="rmsSessionFactory" />
</bean>

What would this look like for Websphere?

A: 
  1. Define "better".
  2. Here are the Spring docs for WebSphere transaction manager. I believe you just change the transaction manager class. You might have to do something special with the factory class as well.
duffymo
I've read a lot of the literature already. I'm looking for answers from someone who has experience or literature that is more specific. I need help understanding better as well. Perhaps Websphere Transaction server is overkill for a single app server application? Thank you all the same.
Mark Glass
I've never used WebSphere, thank God. You're on your own there. My take would be that it's best to use the transaction manager that's written for your app server. I use WebLogic and JBOSS, and those determine my TX manager.
duffymo
+2  A: 

You should probably pipe your transactions through JTA, even if you're using a different implementation behind the scenes. (Hibernate, Webphere, Weblogic, etc). Ideally, it should look like this:

<bean id="transactionImpl" class="org.springframework.transaction.jta.WebSphereTransactionManagerFactoryBean"/>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager ref="transactionImpl"/>
</bean>

If you wanted to use Hibernate's transaction manager instead, just replace the transactionImpl bean's class to the hibernate one in your original question.

As for which manager is better, I honestly can't think of any significant reasons to choose one over the other. The only thing I can think of is it may come into play if you have clustered application servers that share the load, rather than simply being a failover. Maybe transactions can be shared across them? I don't know. If someone can think of something else, feel free to correct me.

EDIT: It looks like WebSphereTransactionManagerFactoryBean (what I used above) doesn't need to be used for WebSphere 6.0 and up, and according to the WebSphere Transaction Manager Spring Docs you should use WebSphereUowTransactionManager as a direct replacement for JTA. So instead of the Hibernate transaction manager in your original example, just use the WebSphereUowTransactionManager class. Spring grabs the transaction manager off of the application server's JNDI tree, so you might have to set some property to specify the JNDI name.

From what I can tell, the WebSphere transaction manager gives you the ability to, among other things, do transaction suspension. Personally I would go with the app server's transaction manager, regardless of whether it was WebSphere or Weblogic or Glassfish or whatever.

Alex Beardsley
Thank you for responding. I have a better idea now what needs to be done. I noticed in the literature that WebSphereUowTransactionManager will only work with Spring 2.1RC1 and higher with WAS 6.0 and higher. Unfortunately we are using Spring 2.0.7.
Mark Glass
Also note that WebSphereTransactionManagerFactoryBean has been removed in Spring 3.0
Jan Kronquist
+1  A: 

I was on a large spring+hibernate+websphere project and the WebsphereUowTransactionManager is the one we ended up on.

The problem is that the default WebsphereTransactionManager uses API's internal websphere API's. The UOW TxManager works great, and you get a little more functionality (we did use the suspend feature for example).

As for the jndi issue, you don't have to worry about setting it, the transaction manager handles it for you.

I would however, highly recommend that you go for the UOW transaction manager see quote from developer works article which addresses the issue of spring+hibernate+websphere.

However, earlier versions (than spring 2.5) of Spring used internal WebSphere interfaces that compromised the ability of the Web and EJB containers to manage resources and are unsupported for application use. This could leave the container in an unknown state, possibly causing data corruption.

You could upgrade your spring version, it's unlikely that you'll have any problems, and if push comes to shove, you could pull just that org.springframework.transaction.jta.WebSphereUowTransactionManager out of spring 2.5 and add it to your application.

Michael Wiles