一些系统信息,它使用Spring,Spring数据,JPA和Hibernate。
我的问题是,2有什么区别?见下文:
//this uses plain JPA, and uses Spring's Transactional
@Transactional(isolation=Isolation.READ_UNCOMMITTED)
public List getData() {
//code
}
//this uses Spring Data
@Lock(LockModeType.None)
public List getData() {
//code
}发布于 2014-11-18 16:09:27
锁定和交易是两件不同的事情,但无论如何.
此隔离级别允许脏读取。一个事务可能会看到其他事务所做的未提交的更改。
/**
* A constant indicating that dirty reads, non-repeatable reads and phantom reads
* can occur. This level allows a row changed by one transaction to be read by
* another transaction before any changes in that row have been committed
* (a "dirty read"). If any of the changes are rolled back, the second
* transaction will have retrieved an invalid row.
* @see java.sql.Connection#TRANSACTION_READ_UNCOMMITTED
*/
READ_UNCOMMITTED可以通过将LockModeType参数传递给接受锁(锁、查找或刷新)的EntityManager方法之一或Query.setLockMode()或TypedQuery.setLockMode()方法来指定锁模式。 锁模式可用于指定乐观锁或悲观锁。
因此,正如它所说的,LockModeType.NONE是注释(JPA,注释左和右)的缺省值,我猜当您使用EntityManager.find(类,对象)时,使用的是默认的LockModeType。
我建议此链接看一些悲观和乐观的锁示例,此链接建议查看事务性示例
https://stackoverflow.com/questions/26985375
复制相似问题