This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

handling ContextSource & DataSource Transaction using @Transactional annotation.

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!