aspose file tools*
The moose likes Other Application Frameworks and the fly likes handling ContextSource & DataSource Transaction using @Transactional annotation. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "handling ContextSource & DataSource Transaction using @Transactional annotation." Watch "handling ContextSource & DataSource Transaction using @Transactional annotation." New topic
Author

handling ContextSource & DataSource Transaction using @Transactional annotation.

Manish Shah
Greenhorn

Joined: Jun 09, 2002
Posts: 22
Hello,

I am newbie in Spring Framework & I am finding using spring very interesting. Currently I am using Spring 2.5.

Coming to my query..

In my application I need to update the user information in LDAP as well as Audit log those information into the database.

For the pupose of using transaction I searched so many ways of performing transaction & found using @Transactional annotation to be suitable currently.
So in my service interface I annotated all the methods with @Transactional.
I also appended <tx:annotationdriven/> element in applicationContext.xml
But during deployment (I use weblogic 9.2 server) i got error saying
"org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager is defined"
I thought the default transaction manager would handle the situation.

Later on I defined a bean :_
<bean id="transactionManager"
class=" org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="contextSource" ref="ldapContextSource"></property>
</bean>

<!-- Get the datasource from above loaded property file. -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>${dataSource}</value>
</property></bean>

<!-- LDAP Bean -->
<bean id="ldapUtil" class="com.***.LdapUtil">
<property name="ldapTemplate" ref="ldapTemplate"></property>
</bean>

<!-- LdapTemplate Bean -->
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<property name="contextSource" ref="ldapContextSource"></property>
</bean>

<!-- Path4 Context Source -->
<bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://***.xxx:31389" />
<property name="base" value="o=***" />
<property name="userDn" value="***" />
<property name="password" value="***" />
</bean>

I want to run both the (LDAP & DB) operation in a single transaction. If either of the operation fails it should rollback. I read in docs that this transactionManager doesnt support two phase commit.
How should I ensure that the transaction I am having is safe & will be roll backed during exception.

Also I would like to know that do we need to specify @Transactional annotation in the furthur following classes like DAOInterface, DAOImpl, LDAPUtil etc.. or only mentioning it service layer will suffice?

Please let me know is my approach correct? I find using TransactionProxyFactoryBean to be very verbose so I wanted to try my hands in annotationdriven.

Thanks..
Manish


SCBCD5, SCWCD, SCJP, MCP
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

I am not answering in order of asked.

Yes, the key thing is that we are moving the transaction demarcation to the service, use case, level, where things like sharing resources throughout the use case call, and managing resources for you. So you only put transaction stuff at the service layer, not in the lower layers.

For two phase commit, you can use the JTA Transaction Manager class instead.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: handling ContextSource & DataSource Transaction using @Transactional annotation.