• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

handling ContextSource & DataSource Transaction using @Transactional annotation.

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
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.

Mark
 
Paper beats rock. Scissors beats tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic