zoukankan      html  css  js  c++  java
  • spring hibernate 事务整合 使用测试类 事务不自动提交的问题!!!

    使用JUnit 测试hibernate 事务管理的时候应注意 ,测试类完成是默认回滚的。 所以只能查询数据库却不能增删改数据库。 应该在测试类上面加上注解 @Rollback(false)  表似默认不回滚。

    package TestHibernate;
    
    import java.util.List;
    
    import javax.annotation.Resource;
    
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.annotation.Rollback;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    import org.springframework.transaction.annotation.Transactional;
    
    import dao.RoomDao;
    import entity.Room;
    
    
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:spring.xml")
    @Transactional
    @Rollback(false)
    public class TestTranscation {
    
    	@Resource
    	private RoomDao r;
    	
    	
    	@Test
    	
    	public void saa(){
    		System.out.println("dsada");
    		List<Room> a = r.findAll();
    		for (Room room : a) {
    			
    			System.out.println(room.getRoomName());
    			room.setRoomName("xxx");
    			r.saveOrUpdate(room);
    		}
    		
    //		Room room=new Room();
    //		room.setId(6);	
    //		room.setRoomName("fsffdsgfdhgf");
    //		r.save(room);
    //		
    	}
    	
    	
    	
    }
    

      

  • 相关阅读:
    day35-python-网络编程
    oc-继承(inherit) 方法重写 继承与组合
    oc-self关键字
    oc-类方法
    oc-封装 get set方法
    oc-匿名对象
    oc-函数命名
    oc-函数,方法,类
    解决"authentication token manipulation error"
    让tomcat自动定位到项目
  • 原文地址:https://www.cnblogs.com/laobiao/p/5631249.html
Copyright © 2011-2022 走看看