transactions

Python SQLite - How to manually BEGIN and END transactions?

限于喜欢 提交于 2019-12-19 09:58:34
问题 Context So I am trying to figure out how to properly override the auto-transaction when using SQLite in Python. When I try and run cursor.execute("BEGIN;") .....an assortment of insert statements... cursor.execute("END;") I get the following error: OperationalError: cannot commit - no transaction is active Which I understand is because SQLite in Python automatically opens a transaction on each modifying statement, which in this case is an INSERT. Question: I am trying to speed my insertion by

Spring + Hibernate +JTA - HibernateTransactionManager or JTATransactionManager

徘徊边缘 提交于 2019-12-19 09:52:45
问题 I want to Integrate Spring and Hibernate and use JTA for managing the transactions. I would also like to delegate transaction handling to the App server, which in my case is JBoss. I have a query regarding the configuration of the " transactionManager " bean in Spring: 1) Can we use HibernateTransactionManager and set the the properties hibernate.transaction.factory_class and hibernate.transaction.manager_lookup_class in hibernate.properties file? If not, why? 2) Or, should we use

JPA and MySQL transaction isolation level

两盒软妹~` 提交于 2019-12-19 09:41:10
问题 I have a native query that does a batch insert into a MySQL database: String sql = "insert into t1 (a, b) select x, y from t2 where x = 'foo'"; EntityTransaction tx = entityManager.getTransaction(); try { tx.begin(); int rowCount = entityManager.createNativeQuery(sql).executeUpdate(); tx.commit(); return rowCount; } catch(Exception ex) { tx.rollback(); log.error(...); } This query causes a deadlock: while it reads from t2 with insert .. select , another process tries to insert a row into t2 .

How to use a single SqlTransaction for multiple SqlConnections in .NET?

独自空忆成欢 提交于 2019-12-19 09:29:17
问题 I have SQL Server 2000, it doesn't support MultipleActiveResults . I have to do multiple inserts, and it's done with one connection per insertion. I want to begin a transaction before all insertions and finish it after all insertions. How do I do it? 回答1: What is the reason you don't use one connection and multiple commands (actually one command recreated in loop)? Maybe this solution will work for you: public static void CommandExecNonQuery(SqlCommand cmd, string query, SqlParameter[] prms)

Configure spring datasource for hibernate and @Transactional

帅比萌擦擦* 提交于 2019-12-19 09:19:42
问题 At this moment I'm using DriverManagerDataSource with @Transactional annotation to manage transactions. But all transactions are very very slow, probably because data source open and close connection to db each time. What data source should I use to speed up transaction? 回答1: DriverManagerDataSource isn't actually a connection pool and should only be used for testing. You should try BasicDataSource from Apache Commons DBCP. Something like: <bean id="dataSource" destroy-method="close" class=

Rails not rolling back transaction after failed save()

心不动则不痛 提交于 2019-12-19 09:14:17
问题 I have this domain model: A user has group of items, and the state of the items can fail a validation. Validation works fine, and I even see exceptions get called when I use save! . In my controller, I have this: @user.items() << item if @user.save render :json => {}, :status => :ok else render :json => {:status => :error, :errors => item.errors}, :status => :bad_request end The first POST succeeds, and the second POST fails, but when I hit the index, I still see two objects, as if the second

Hibernate versioning parent entity

眉间皱痕 提交于 2019-12-19 08:55:19
问题 Consider two entities Parent and Child. Child is part of Parent's transient collection Child has a ManyToOne mapping to parent with FetchType.LAZY Both are displayed on the same form to a user. When user saves the data we first update Parent instance and then Child collection (both using merge). Now comes the tricky part. When user modifies only Child property on the form then hibernate dirty checking does not update Parent instance and thus does not increase optimistic locking version number

Transaction rollback doesn't work

杀马特。学长 韩版系。学妹 提交于 2019-12-19 08:34:19
问题 I have made a database wrapper with extra functionality around the PDO system (yes, i know a wrapper around a wrapper, but it is just PDO with some extra functionality). But i have noticed a problem. The folowing doesn't work like it should be: <?php var_dump($db->beginTransaction()); $db->query(' INSERT INTO test (data) VALUES (?) ;', array( 'Foo' ) ); print_r($db->query(' SELECT * FROM test ;' )->fetchAll()); var_dump($db->rollBack()); print_r($db->query(' SELECT * FROM test ;' )->fetchAll(

Transaction rollback doesn't work

两盒软妹~` 提交于 2019-12-19 08:34:08
问题 I have made a database wrapper with extra functionality around the PDO system (yes, i know a wrapper around a wrapper, but it is just PDO with some extra functionality). But i have noticed a problem. The folowing doesn't work like it should be: <?php var_dump($db->beginTransaction()); $db->query(' INSERT INTO test (data) VALUES (?) ;', array( 'Foo' ) ); print_r($db->query(' SELECT * FROM test ;' )->fetchAll()); var_dump($db->rollBack()); print_r($db->query(' SELECT * FROM test ;' )->fetchAll(

Transaction rollback doesn't work

吃可爱长大的小学妹 提交于 2019-12-19 08:34:06
问题 I have made a database wrapper with extra functionality around the PDO system (yes, i know a wrapper around a wrapper, but it is just PDO with some extra functionality). But i have noticed a problem. The folowing doesn't work like it should be: <?php var_dump($db->beginTransaction()); $db->query(' INSERT INTO test (data) VALUES (?) ;', array( 'Foo' ) ); print_r($db->query(' SELECT * FROM test ;' )->fetchAll()); var_dump($db->rollBack()); print_r($db->query(' SELECT * FROM test ;' )->fetchAll(