TransactionSystemException: Could not roll back Hibernate Transaction; Transaction not started

异常信息:

TransactionSystemException: Could not roll back Hibernate Transaction; Transaction not started

解决办法:

@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:resources/applicationContext.xml","classpath:resources/applicationConfig.xml"})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = false)
@Service
public class HibernateTest4 {
	private static Logger LOG = Logger.getLogger(HibernateTest4.class);
	@Autowired
	SessionFactory sessionFactory;
	@Autowired
	HibernateTemplate hibernateTemplate;

	
	@Test
	@Transactional
	public void test(){
		Demo demo  = new Demo();
		demo.setName("wwwzy123");
		Session session  =  sessionFactory.getCurrentSession();
		session.save(demo);
		session.flush();
		//交给spring,就不要再关闭了
//		session.close();
	}
	
	@Test
	@Transactional
	public void test2(){
//		String log4jPath=System.getProperty("user.dir")+"/src/main/java/resources/log4j.properties";
//	    PropertyConfigurator.configure(log4jPath);
		LOG.error("SessionListener contextInitialized!");  
		Demo demo  = new Demo();
		demo.setName("wwwzy001");
		System.out.println(hibernateTemplate);
		hibernateTemplate.persist(demo);
		hibernateTemplate.flush();
	}

}


你可能感兴趣的:(TransactionSystemException: Could not roll back Hibernate Transaction; Transaction not started)