diff --git a/src/main/java/nl/nn/testtool/Config.java b/src/main/java/nl/nn/testtool/Config.java index 0599af1a..898ca5ca 100644 --- a/src/main/java/nl/nn/testtool/Config.java +++ b/src/main/java/nl/nn/testtool/Config.java @@ -27,7 +27,9 @@ import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.SimpleDriverDataSource; +import org.springframework.transaction.TransactionManager; import io.quarkus.arc.DefaultBean; import nl.nn.testtool.echo2.ComparePane; @@ -229,6 +231,14 @@ DataSource dataSource() { return new SimpleDriverDataSource(); } + @Bean + @Scope("prototype") + TransactionManager transactionManager(DataSource dataSource) { + DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); + transactionManager.setDataSource(dataSource); + return transactionManager; + } + @Bean @Scope("prototype") JdbcTemplate jdbcTemplate(DataSource dataSource) { diff --git a/src/main/java/nl/nn/testtool/storage/database/DatabaseStorage.java b/src/main/java/nl/nn/testtool/storage/database/DatabaseStorage.java index b3e7bf9e..adc083cb 100644 --- a/src/main/java/nl/nn/testtool/storage/database/DatabaseStorage.java +++ b/src/main/java/nl/nn/testtool/storage/database/DatabaseStorage.java @@ -40,6 +40,8 @@ import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.PreparedStatementSetter; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.annotation.Transactional; import lombok.Getter; import lombok.Setter; @@ -57,6 +59,15 @@ /** * @author Jaco de Groot */ +// With transaction manager configured auto-commit is disabled and PostgreSQL will not throw the following exception +// on insert of a report: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode. +// Without proxyTargetClass = true the test webapp will give: Bean named 'proofOfMigrationStorage' is expected to be of +// type 'nl.nn.testtool.storage.proofofmigration.ProofOfMigrationStorage' but was actually of type 'jdk.proxy3.$Proxy26' +// It would also be possible to set auto-commit to false on Connection(Pool) or DataSource level but then still a +// transaction manger needs to be configured for JdbcTemplate to commit changes. Otherwise everything seems to be +// working fine (logging shows insert query) but no data appears in database and debug tab. +@EnableTransactionManagement(proxyTargetClass = true) +@Transactional // @Dependent disabled for Quarkus for now because of the use of JdbcTemplate public class DatabaseStorage implements LogStorage, CrudStorage { private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());