• 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

@Transactional and mysql autocommit behaviour using managers/daos

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody.
I want to apologize if the title is not clear, but really I don't know how to be clear in few word. I want to apologize also if I posted in the wrong section . And my last apology is for a possible duplicated question..I swear I've searched the forum, but I've found no solution.
Suppose you are in the following situtation:

where the transactionalMethodUsingDao() perform an insert into mysql DB in a for loop.
Mysql logs show something like:

Now suppose that the transactional method you are calling is the same class, so that:

This lead to a log like:

My question is: why? I've read the documentation but clearly I've missed something since is not clear to me why the two code act in a different manner.
The same applies for managers that call an insert operation through a DAO.
Thanks
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Transactional is a marker interface that Spring uses to apply advice to the method. By default an interface based proxy advice mechanism is used. This means the @Transactional must be on a public method and must be exposed through and interface and called through that interface (no self calls within the same class).

There are ways around this. There was a question a year back about this sort of thing. See if it helps you at all.

https://coderanch.com/t/596257/aop/Spring-AOP#2719658


If this is being used within a test case for integration tests have a look at the following:
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#testing-tx
reply
    Bookmark Topic Watch Topic
  • New Topic