Java程序设置脏读

1. 纯的JDBC写法,通过Connection设置为脏读
   
     conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
     conn.setReadOnly(true);//如果不操作数据库,可设置只读

2.支持Transactional注解的框架,直接在方法上加注解即可

@Transactional(isolation = Isolation.READ_UNCOMMITTED,readOnly=true) 

3.Spring中配置

 
        
        
        
        
            
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED
                PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,readOnly
                PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,readOnly
                PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,readOnly
                PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,readOnly

                

                 

                        PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,readOnly

                

                PROPAGATION_REQUIRED
            
        
    

4.hibernate中session方法

Sesssion session = this.getSessionFactory().getCurrentSession();
//sesion.connection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);//已过期 
SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);



你可能感兴趣的:(JavaWeb)