Jan 16th, 2009, 10:45 AM
Create a new Transactionnal Component
I have created a new java component which can perform internal commit and rollback. I now would like to have it managed by spring's TransactionManager which uses the application server transaction manager so that when another resource fails, my component can rollback or commit accordindly.
How am I to do this?
I've looked up the spring source code and doc on declarative and programmatic approach, but don't find a solution.
As I understand it, declarative approach with Weblogic JTA means every JTA resource managed by Application server is automatically watched. How about adding non Application Server watched resources? A way to do so, would be to adapt my component to J2EE JCA architecture and bind it with JNDI so that Application Server watches this resource, but this is heavy. Since my component is created by spring, is there an easier way? (Something related to implementing UserTransaction for example)
Programmatically, I've seen resources can be added by using DataSourceUtils, SessionFactoryutils to incorporate resources in Transaction manager. In my case, with my new component, do I need to write a new TransactionManager specifically for it, plus do the equivalent of DataSourceUtils?
Jan 19th, 2009, 05:52 AM
Well, I think, I've found the answer to my question! So I'm sharing it with you:
I created a service that is transactionnal and wanted it to be monitored by springs transaction manager.
Spring's transaction manager JPA, JDBC, are configured by spring config file. (by setting DataSource as property). Since I'm not using a standard DataSource, this approach, isn't usefull. So left remains only JTATransactionManager. Transactionnal resources are added through JNDI. In short, calling an XA resource with JNDI causes the resource to be monitored by JTATransactionManager. My service is a spring service which isn't accessible through JNDI. So there are only two options two me: make my service available through JCA and declared in JNDI, or write my own Transaction Manager.
The best would be to create my own Transaction Manager, but because of time constraints, I'll probably stick with creating a JCA component.