How to rollback a database transaction when testing services with Spring in JUnit?

You need to extend transaction boundaries to the boundaries of your test method. You can do it by annotating your test method (or the whole test class) as @Transactional: @Test @Transactional public void testInsert(){ long id=myService.addPerson(“JUNIT”); assertNotNull(id); if(id<1){ fail(); } } You can also use this approach to ensure that data was correctly written before … Read more

Are PostgreSQL functions transactional?

PostgreSQL 12 update: there is limited support for top-level PROCEDUREs that can do transaction control. You still cannot manage transactions in regular SQL-callable functions, so the below remains true except when using the new top-level procedures. Functions are part of the transaction they’re called from. Their effects are rolled back if the transaction rolls back. … Read more

Continuing a transaction after primary key violation error

You can also use SAVEPOINTs in a transaction. Pythonish pseudocode is illustrate from the application side: database.execute(“BEGIN”) foreach data_row in input_data_dictionary: database.execute(“SAVEPOINT bulk_savepoint”) try: database.execute(“INSERT”, table, data_row) except: database.execute(“ROLLBACK TO SAVEPOINT bulk_savepoint”) log_error(data_row) error_count = error_count + 1 else: database.execute(“RELEASE SAVEPOINT bulk_savepoint”) if error_count > error_threshold: database.execute(“ROLLBACK”) else: database.execute(“COMMIT”) Edit: Here’s an actual example of … Read more

Database.BeginTransaction vs Transactions.TransactionScope [duplicate]

I found out the answer in Entity Framework 6’s documentation: With the introduction of EF6, Microsoft recommends to use new API methods: Database.BeginTransaction() and Database.UseTransaction(). Although System.Transactions.TransactionScope is still very well supported, it is no longer necessary for most users of EF6. While Database.BeginTransaction() is used only for database related operations transaction, System.Transactions.TransactionScope, in addition … Read more

The matching wildcard is strict, but no declaration can be found for element ‘tx:annotation-driven’

You have some errors in your appcontext.xml: Use *-2.5.xsd xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd” Typos in tx:annotation-driven and context:component-scan (. instead of -) <tx:annotation-driven transaction-manager=”transactionManager” /> <context:component-scan base-package=”com.mmycompany” />

Do you need a database transaction for reading data?

All database statements are executed within the context of a physical transaction, even when we don’t explicitly declare transaction boundaries (BEGIN/COMMIT/ROLLBACK). If you don’t declare transaction boundaries, then each statement will have to be executed in a separate transaction (autocommit mode). This may even lead to opening and closing one connection per statement unless your … Read more

How to display open transactions in MySQL

How can I display these open transactions and commit or cancel them? There is no open transaction, MySQL will rollback the transaction upon disconnect. You cannot commit the transaction (IFAIK). You display threads using SHOW FULL PROCESSLIST See: http://dev.mysql.com/doc/refman/5.1/en/thread-information.html It will not help you, because you cannot commit a transaction from a broken connection. What … Read more

How to enable INNODB in mysql

You need to enable it in my.cnf file, then restart your server: http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#option_mysqld_innodb Or you can load an InnoDB plugin during runtime: https://docs.oracle.com/cd/E19078-01/mysql/mysql-refman-5.1/storage-engines.html#replacing-builtin-innodb