Reputation: 69
Let's say I am implementing an online library system using the CRUD method with Hibernate and Spring. How do I ensure the system follows ACID? I do need some locking mechanism to prevent concurrency problems, right?
Upvotes: 0
Views: 242
Reputation: 47300
Declare transactions on your service layer methods, it will look something like this
@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void edit(MyDomain myDomain) {
// perform your db stuff, with hibernate or sql
Then in your config somethign like :
<!-- Declare a transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory"/>
Also use a readOnly lock when only doing reads.
Upvotes: 2
Reputation: 485
Spring provides 'DEFAULT' Isolation strategy which use the default transaction level of the underlining data store. eg : 'READ_COMMITTED' for Oracle.
If you are concerned about concurrency, you can change the transaction isolation level from default to SERIALIZABLE. This is the highest level of isolation. Highest isolation can increase the chances for deadlock and hence performance issues.
'DEFAULT' is more than enough for most of the use cases including CRUD Operatins.
Upvotes: 0