transactions

How to manually lock and unlock a row?

不羁岁月 提交于 2019-12-24 13:27:50
问题 I am trying to circumvent double-writes by locking and unlocking certain rows. I have a table personnel and as soon as a user tries to edit a row, I want to lock that row. So BEGIN; // I guess I have to lock it somehow here SELECT * FROM personnel WHERE id = 12; COMMIT; and once an edit as been made, I want to submit the UPDATE in the same style: BEGIN; //Unlocking UPDATE personnel SET ... WHERE id = 12; COMMIT; In the time between, when another user tries to edit the same row, he would get a

How to make a transaction in asp.net-core 2.0?

荒凉一梦 提交于 2019-12-24 12:14:04
问题 I want to update some values but in case one fails I need to rollback. How can I do this in asp.net-core-2.0? I have not found any answers yet. Is this because it is not yet supported? In that case what are some alternatives? 回答1: Yes man, using System.Transactions.TransactionScope, available since .Net Core 2.0 and above. check this: Using System.Transactions in ASP.NET: https://msdn.microsoft.com/en-us/ms229977 Implementing an Implicit Transaction using Transaction Scope: https://msdn

Lazy Loading error

余生颓废 提交于 2019-12-24 12:05:06
问题 I know that this issue was already raised here several time. However I couldn't find any solution which will help so I decided to post it again. I'm using Hibernate with Spring MVC framework and I'm trying to fetch my class wth sub class: public class Scene implements Serializable{ private Long id; private Author author; //omitting getters and setters } public class Author{ private Long id; Private String name; //omitting getters and setters } My Hibernate configuration is the following:

Inconsistent JPA behavior using no transaction, propagation SUPPORTS and OpenEntityManager pattern

不羁岁月 提交于 2019-12-24 11:24:36
问题 We are using JPA (Hibernate 4) with Spring 4 managing the JTA transactions. To allow lazy initialization even when simply reading from the database without any transaction we added the "OpenEntityManager" pattern. You can find a test case for these questions on GitHub https://github.com/abenneke/sandbox/tree/master/spring-hibernate4-transaction We know that there is a difference between having no transaction synchronization at all and SUPPORTS synchronization. But the JPA behaviour seems to

Entity Framework - Issues in DbContextTransaction.Rollback()

落爺英雄遲暮 提交于 2019-12-24 11:08:32
问题 I connected the database using Entity Framework . I Implemented a Contact Repository to Save the Contact Information (Sample Repository). In the Said Class file, I declared a static property for handling DBEntities (i.e., BLabsEntities ) namely " Context " and also declared a static property for DbContextTransaction . In the following code I added a try catch block to handle Exceptions of Entity Framework in the SaveContact() Repository method. I Initiated a transaction before starting the

when to prefer pessimistic model of transaction isolation over optimistic one?

微笑、不失礼 提交于 2019-12-24 10:58:25
问题 Do I understand correctly that table/row lock hints are being used for pessimistic transaction (TX) isolation models of concurrency ONLY ? In other words, when can table/row lock hints be used during engagement of optimistic TX isolation provided by SQL Server (2005 and higher)? When one would need pessimistic TX isolation levels/hints in SQL Server2005+ if the later provides built-in optimistic (aka snapshot aka versioning) concurrency isolation? I did read that pessimistic options are

@Transactional annotation required due to 'org.hibernate.HibernateException: No Session found for current thread' exception

纵然是瞬间 提交于 2019-12-24 10:24:57
问题 So, I read that the best place to put the @Transactional annotation was outside the DAO classes which contains the db access methods, like in a service class which use those methods. Now, the problem is, once I've already remove this annotations from the DAO classes, I launch the DAO test methods and the aforementioned exception raised. I put back the annotations in the DAO classes and this exception doesn't raises anymore. Then my question is: how can I clear my DAOs of this annotations and

Unique email in Google Datastore

自作多情 提交于 2019-12-24 10:08:54
问题 I have a User entity containing an Email field. The User entity id is a ULID, because I want to allow users to change their email addresses, but I want to ensure that the email address is unique on both a CREATE and an UPDATE . I am using Datastore transactions. This is a code fragment: ctx := context.Background() k := datastore.NameKey("User", user.ID, nil) _, err := client.RunInTransaction(ctx, func(t *datastore.Transaction) error { // other stuff that needs to be in transaction _, err = t

How to make the queries in a stored procedure aware of the Spring Transaction?

别等时光非礼了梦想. 提交于 2019-12-24 09:59:29
问题 After I execute a bunch of queries on the DB, I'm calling a stored procedure from a Spring Transaction (a Spring Service marked with @Transactional). entityManager.createNativeQuery("call stored_procedure()"); query.executeUpdate(); In order to make the queries of the stored procedure rollback when an exception is thrown by the java code (or the modifications of the DB made in the javacode rolled back because of an exception thrown in the stored procedure), I've set the autocommit variable of

Spring nested transaction rollback after handling exception

ε祈祈猫儿з 提交于 2019-12-24 09:45:12
问题 I have a @Service class which has a @Transactional method that calls another @Transactional method on the another service. Something like that: @Service public class AService { @Autowired BService b; @Autowired ARepository aRepo; @Transactional public void methodOne(){ try{ b.methodTwo(); }catch(RuntimeException e){} aRepo.save(new A()); } } @Service public class BService{ @Transactional public void methodTwo(){ if(true) throw new RuntimeException(); } } I expect that A entity will be insert,