3

I'm using the update method in NamedParamameterJdbcTempalte which implements this org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations.

I looked up the docs and the only thing I can find is "this method issues an update via a prepared statement, binding the given arguments."

I have code that looks like this

//Calling jdbcTemplate.update() here on Foo objects
//Calling another update on the same set of Foo objects (I know it's dump but let's just leave it as is)

Now my question is will the first update wait until the transaction is completed then return, or it will just issue that request and return? When I get to the second line, do I have any guarantee that the transaction issued by the first call to update has completely finished?

I seem to be seeing mysql deadlock once in a while and I suspect that's because the first update has not finished its job when the second one comes in.

Found this question, but the answer doesn't really answer my question. How to avoid mysql 'Deadlock found when trying to get lock; try restarting transaction'

Community
  • 1
  • 1
0x56794E
  • 20,883
  • 13
  • 42
  • 58
  • The method does what it's documented to do: it executes a statement. Nothing more. – JB Nizet Aug 15 '13 at 20:54
  • right. we know that. but when I get to the next line of code, do I have any guarantee that the first transaction has completely finished? – 0x56794E Aug 15 '13 at 20:57
  • Which first transaction? The statement is executed in the context of the current Spring-managed transaction. I repeat: the method does what it's documented to do: it executes a statement. Nothing more. So it doesn't start a transaction, and doesn't commit a transaction either. – JB Nizet Aug 16 '13 at 07:32

0 Answers0