0

Could anyone tell us what happens to the changes done to database tables in a method that is not annotated as @Transactional but the transaction manager is annotation-driven?

We assume it's up to the auto commit true or false. If auto commit is true, will the data changes be committed immediately after the method is finished?

Thanks for any help in advance.

user2616361
  • 11
  • 1
  • 2

1 Answers1

0

It really depends on the call stack and what you do in that method. If you're using things like JdbcTemplate or DataSourceUtils, a non annotated method might reuse the context of a transaction that was started higher in the call stack hierarchy. Similarly, if your method tries to lookup the connection directly on a non-managed DataSource, even a method marked with the annotation will not give you the expected result.

Assuming that your method is not trying to access some resources directly, your non annotated method may or may not be transactional depending on its call stack which is probably something you want to avoid unless you know in which context this method is invoked.

On a side node, there are various ways to ensure that the transactional context is at the proper stage before entering an annotated method, see the javadoc of Propagation for more details

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89