transactions

apparent transaction isolation violation in postgresql

穿精又带淫゛_ 提交于 2019-12-24 04:35:15
问题 I am using PostgreSQL 9.3.12 on CentOS Linux. I have two processes connecting to the same database, using a default transaction isolation level of "read committed". According to the postgres docs, one process in a transaction should not "see" changes made by another process in a transaction until they are committed. A sequence I am seeing is: process A starts its transaction process A deletes everything from table T process B starts its transaction process B attempts a select for update on

How to force flushing in Grails GORM

孤者浪人 提交于 2019-12-24 03:51:50
问题 I have a service that distributes tasks to operators. Inside a method I distribute many tasks in time inside a loop. I want to flush the task, the operator, and a DistributionLog. If I just had one domain to save I think I could do something like Operator.withTransaction{ //...some code } but I have at least 3 domains to save and to make it even worse, two of them have dependency on each other. The operator have a list of tasks. I can't wait all the distribution to finish before an operator

Spring Data/Hibernate MS SQL Server unique constraint and race condition

筅森魡賤 提交于 2019-12-24 03:23:42
问题 Some time ago I ran into the race condition issue when 2 separate transactions try to simultaneously check if the record exists(by 4 fields) and if no - create a new one. My environment: MS SQL Server , Spring Data / JPA / Hibernate It was a duplicate records issue. I implemented the test that simulates concurrent calls and thus was able(pretty stable at 99.99% of execution times) to reproduce this issue. Right now I'm fixed this issue by applying unique constraint over these 4 fields. At

How SQL Server handles UPDATE transactions?

。_饼干妹妹 提交于 2019-12-24 03:14:13
问题 We have a table which is used to Generate Unique Numeric keys. These keys are then used as a PrimaryKey in other tables. Table structure is like this: TableName VARCHAR CurrentKey INT So we have data in this table like TableName Customers CurrentKey 400 So when we need next primary key for table Customers we get the CurrentKey from this table where TableName is Customers , it will give us 400 we increment (400+1) it and we update this key in the table also. So our CurrentKey is 401 now. The

PostgreSQL transaction restart

狂风中的少年 提交于 2019-12-24 03:02:14
问题 I'm starting to play with PostgreSQL and noticed that sequence s never rollback, even on failed INSERT . I've read that it is as expected to prevent duplicated sequences on concurrent transactions and I found that weird as my database experience is only with GTM where transaction restarts are common and used precisely for this. So I wanted to test restarts in PGSQL and loaded this in a database: CREATE SEQUENCE account_id_seq; CREATE TABLE account ( id integer NOT NULL DEFAULT nextval(

MVC 5 IdentityDbContext and DbContext transactions

寵の児 提交于 2019-12-24 03:00:24
问题 I work on a MVC 5 project with EF6.1. As a beginner, I try to keep the code generated by the MVC 5 template in order to use the default authentification system with AccountController. However, I had to add some classes, like "User.cs" as below, so I'm using Entity Framework Data Model. public partial class User { public User() { this.Logs= new HashSet<Log>(); } public int IdUser { get; set; } public string AspNetUsersId { get; set; } //References to AspNetUsers.Id public string Title { get;

For a writeless transaction which is cheaper/quicker: COMMIT or ROLLBACK?

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:43:14
问题 I'm using sql transactions as containers for APPLOCKS and other concurrency mechanisms and so I sometimes create transactions at various isolation levels which only read data and don't write. I believe that in these situations, logically, COMMIT and ROLLBACK have identical outcomes. For performance reasons, I'd like to know which one is cheaper/quicker for the server to execute? Is unavoidable bookkeeping required that is optimized for the COMMIT case and additional overhead for ROLLBACK even

Incremented DB Field

主宰稳场 提交于 2019-12-24 02:38:15
问题 Let's say that I have an article on a website, and I want to track the number of views to the article. In the Articles table, there's the PK ID - int, Name - nvarchar(50), and ViewCount - int. Every time the the page is viewed, I increment the ViewCount field. I'm worried about collisions when updating the field. I can run it in a sproc with a transaction like: CREATE PROCEDURE IncrementView ( @ArticleID int ) as BEGIN TRANSACTION UPDATE Article set ViewCount = ViewCount + 1 where ID =

Using TransactionScope with System.Data.OracleClient - TransactionAbortedException

我的未来我决定 提交于 2019-12-24 01:53:22
问题 My system write some data to a SQL Server DB (2008), extracts it later and processes it some more, before writing it to an Oracle (10g) DB. I've wrapped my SQL Server interactions in a TransactionScope but when I try the same think with my Oracle interactions I get a `TranactionAbortedException - "The transaction has aborted". Remove the TransactionScope, and everything works OK. I could always revert back to manually managing my own transactions, but I'm hoping there is a simple solution.

Is it good practice to always use a TransactionScope in a DAL base class?

匆匆过客 提交于 2019-12-24 01:06:12
问题 I have a DAL base class which centralises all the database calling code in my app. I want to ensure that all insert/update/delete actions are wrapped in a transaction, irrespective of whether it was written into the SP or not. Would it be good practice to wrap my 'ExecuteNonQuery' DAL method in a TransactionScope or would I be adding a lot of overhead for db calls that don't require it. I'm happy with using a TransactionScope furthur up the in the UI when required to wrap multiple service