• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Spring transaction using AOP

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I have a question regarding spring transaction using AOP.
I can able to declare an transaction advice in spring.xml and able to apply the advice to respective methods using pointcut.




Here transactionAdvice(txAdvice) is applied to all methods starting with book present in org.simple.service.TicketBookingService.



But,

I would like to use annotation.So what i did is

This is also working fine.

Now what I feel is,here @Transactional is repeated in all methods which is starting with book.So i would like to put in some common area.
So I did the following,

1.
in spring.xml,by mentioning this spring will scan for aspect components.

2.
I created a class called TransactionLoggingAspect.





My question is,
what is the annotation equivalent of the above "txAdvice"?
In TransactionLoggingAspect.java,Where I can put the annotation equivalent?

In spring tutorial,
http://static.springsource.org/spring/docs/3.0.x/reference/transaction.html
they have mentioned for XML part,which is working fine.
But I am searching for annotation part.But not found.

Please help me in this issue.

Regards,
Anand
 
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
To use @Transactional Annotations. Your config has to have <tx:annotation-driven/> And you need to have a transactionManager bean. That is all. Now you can put @Transactional on any service method and it will be transactional.

No need for any aop or aspect classes. Everything that you did before in xml is taken care of. That is why using annotations for Transactional methods is so much easier than using xml for it.

Mark
 
Anand Sivathanu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:To use @Transactional Annotations. Your config has to have <tx:annotation-driven/> And you need to have a transactionManager bean. That is all. Now you can put @Transactional on any service method and it will be transactional.

No need for any aop or aspect classes. Everything that you did before in xml is taken care of. That is why using annotations for Transactional methods is so much easier than using xml for it.

Mark



Hi Mark Spritzler,
Thanks for your comment. I understood your comment and totally agree with that.
My question here is,
I keep on put @Transactional for any service methods that i needed.I feel lazy to put @Transactional also.
Instead I would like to put in some common area @Transactional and declare that methods starting with book*(bookBusTicket,bookPlaneTicket,bookTrainTicket) present in org.simple.service.TicketBookingService class.
This I can put in xml as


But I would like in programmatic way.(@Transactional in common area and declare methods starting with book*(bookBusTicket,bookPlaneTicket,bookTrainTicket) present in org.simple.service.TicketBookingService class)
Is there any programmatic way?(May be annotation or something)
(My question may be wrong.correct me if i am wrong)

Regards,
Anand
 
Mark Spritzler
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
Well, you can put @Transactional on the class level and then all methods from your interfaces that that class implements are now all transactional.

That is a way to put the annotation in once and get many methods covered.

So one trick it to make sure you put all those methods that start with into a single interface that that class implements. Or just put @Transactional on that interface.

Mark
 
Anand Sivathanu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mark Spritzler wrote:Well, you can put @Transactional on the class level and then all methods from your interfaces that that class implements are now all transactional.

That is a way to put the annotation in once and get many methods covered.

So one trick it to make sure you put all those methods that start with into a single interface that that class implements. Or just put @Transactional on that interface.

Mark



Oh.
You are telling to put @Transaction in the class level or interface level

1.
class level - flavor 1


2.
interface level - flavor 2


These are the two flavors you are coming to say. Am I right?

Regards,
Anand
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic