一些系统信息,使用Spring,Spring Data,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
}
答案 0 :(得分:1)
锁定和交易是两回事,但无论如何......
此隔离级别允许脏读。一个事务可能会看到某些其他事务所做的未提交的更改。
/**
* 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方法的参数(lock, 查找或刷新)或查询.setLockMode()或 TypedQuery.setLockMode()方法。
锁定模式可用于指定乐观或悲观 锁。
因此,正如它说LockModeType.NONE是注释的默认值(JPA,注释左右)我想当你使用EntityManager.find(Class,Object)时,会使用默认的LockModeType。