• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction Management in Spring with SERVICE and DAO layers?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to apply different PROPAGATION transaction attributes for methods in SERVICE and DAO layers using Classic Spring AOP(i.e using TransactionProxyFactoryBean)?

Below Example is using @Transactional annotation. I would like know How to apply the same using TransactionProxyFactoryBean(Spring 1.x) (or) Transaction Advices (Spring 2.x i.e <tx:advice> and <aop:config>)

//Service Interface


//Service Implementation





//DAO Interface


//DAO Implementation


//beans.xml


// example beans.xml with TransactionProxyFactoryBean .
Here I could able to configure "transactionAttributes" for only Service(i.e Cashier) methods . How to apply "transactionAttributes" differently for DAO(i.e BookShop) methods like we did using @Transactional Annotation ? and the same with <tx:advice> ,<aop:config> ?


// example beans.xml using Trasaction Advices(Spring 2.x way)
 
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


look at the attributes of tx:method. It includes all the attributes of the @Transactional annotation.

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

Mark Spritzler wrote:

look at the attributes of tx:method. It includes all the attributes of the @Transactional annotation.

Mark





sorry Mark, I have placed "cashier" instead of "chechout" in <tx:method>


moreover in <tx:method> "checkout" is the name of the method in Cashier interface(i.e Service layer) & for that "checkout" method we are applying default transaction attributes. Now I would like to apply like <tx:method name="purchase" propagation="REQUIRES_NEW"/> <-- "purchase" is BookShop (DAO layer) interface method.

can I configure like the below? please help me in this.




even I tried the above one, but it is not working correctly.

Initial data in the tables

SQL> select * from BOOK;

ISBN BOOK_NAME PRICE
---------- ------------------------- ----------
0001 The First Book 30
0002 The Second Book 50

SQL> SELECT * FROM BOOK_STOCK;

ISBN STOCK
---------- ----------
0001 10
0002 10

SQL> SELECT * FROM ACCOUNT;

USERNAME BALANCE
-------------------------------------------------- ----------
user1 40

After the below operation execution



The data in the tables should be like

SQL> select * from BOOK;

ISBN BOOK_NAME PRICE
---------- ------------------------- ----------
0001 The First Book 30
0002 The Second Book 50

SQL> SELECT * FROM BOOK_STOCK;

ISBN STOCK
---------- ----------
0001 9
0002 10

SQL> SELECT * FROM ACCOUNT;

USERNAME BALANCE
-------------------------------------------------- ----------
user1 10


because, there should be one successful Transaction of First time purchase("0001","user1") method execution. But when run the above code with that configuration (<tx:advice>) in beans.xml I am not getting the first purchase()'s transaction successfully to get the data in DataBase as show above.


Please help me in this?

Thanks
RaoPotla

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just what I said, the tx:method tag has attributes for propagation.

If you haven't used tx:method before, then check it out in the SpringFramework.org Spring Framework Documentation under the transactions section.

here shows the settings
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-txadvice-settings

and here is an example
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-first-example

and here is another example
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-diff-tx

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


Thank you very much Mark, the following URL is very helpful for me & this is what I am looking for.

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-diff-tx
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic