隔离级别Read_Committed不起作用

时间:2019-01-22 10:46:05

标签: mysql spring hibernate

我想测试隔离Read_Committed。我为外部事务添加了Propogation.Required,为内部事务添加了隔离Read_Committed。但是在进行外部事务之前,我可以获取记录。下面是我的代码

@Service
public class CustomerManagerImpl implements CustomerManager {

@Autowired
private CustomerDAO customerDAO;

public void setCustomerDAO(CustomerDAO customerDAO) {
    this.customerDAO = customerDAO;
}

@Transactional(readOnly=false)
public void createCustomer(Customer cust) {
    customerDAO.create(cust);
}

@Transactional(readOnly=false)
public void createAddress(Address add) {
    customerDAO.createAdd(add);

}
//@Transactional
@Transactional(isolation =Isolation.READ_COMMITTED)
public void findCustomer(int id) {
customerDAO.findCustomer(id);

}

外部交易的帮助类:

@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = Exception.class)

public void saveObject() {
    Customer cust = createDummyCustomer();
    customerManager.createCustomer(cust);
    customerManager.findCustomer(2);
    Address add =createDummyAddress();
    customerManager.createAddress(add);
}

0 个答案:

没有答案