Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

handling ContextSource & DataSource Transaction using @Transactional annotation.

Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>

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

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

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

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

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.

Posts: 17346
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic