I have been at this for a good few hours and I can not find a way to get around what seems to be JPARepository automatically starting/committing a transaction when I save en
MySQL historically by default created tables using the MyISAM engine, which didn't support transactions. Later InnoDB was added which did support transactions, however MyISAM remained the default for quite some time.
Hibernate with its dialects followed the same defaults and hence the default for the MySQL dialect is MyISAM (for backwards compatibility).
You have 2 ways to fix this, either select a specific dialect or toggle from MyISAM to InnoDB with a specific property.
To select a dialect use the spring.jpa.database-platform
to specify the required dependency.
spring.jpa.database-platform=org.hibernate.dialect.MySQL57InnoDBDialect`
or to set the property use
spring.jpa.properties.hibernate.dialect.storage_engine=innodb
or a combination of both (as the MySQL57InnoDBDialect
is deprecated now that there is the hibernate.dialect.storage_engine
property).
spring.jpa.database-platform=org.hibernate.dialect.MySQL57Dialect
spring.jpa.properties.hibernate.dialect.storage_engine=innodb
See also: https://in.relation.to/2017/02/20/mysql-dialect-refactoring/