Last Updated: February 25, 2016
· samspot

Spring @Transactional(readOnly=true) & MySQL Replication

When using the com.mysql.jdbc.ReplicationDriver with @Transactional annotations, you may encounter some strange behavior. I recently learned that marking a method read-only will stop it from writing anything to the database but w/o throwing any kind of error message.

It appears that with Hibernate, the read only transaction advice will cause it to set the connection to never flush. So instead of giving an error message the session will end w/o commiting the write.

I found this behavior surprising and thought I would share it in case anyone else is using this driver for transactions.