Spring整合hibernate中,org.hibernate.HibernateException: Could not obtain transaction-synchronized 问题

想做一个项目,搭建SSH环境,在整合Spring和Hibernate期间遇到了一个问题,特此记录一下sessionFactory.getCurrentSession()出现的错误

在进行Junit Test时,抛出org.hibernate.HibernateException: Could not obtain transaction-synchronized,无法获得事务同步

解决办法可以采用注解式声明,添加事务管理器。在service层上添加@Transactional()注解,当然也可以通过其属性设置其ACID特性(
暂不设置,有需要可以自己设置)

	@Service("userService")
	@Transactional()
	public class UserServiceImpl extends BaseServiceImpl {
	
		@Resource(name="userDao")
		public void Setbd(basedao dao  ){
			super.Setbd(dao);
		}
	.
	.
	.
在配置文件中添加标签,使事务注解生效

```

```

再次运行后,错误消失

你可能感兴趣的:(Spring整合hibernate中,org.hibernate.HibernateException: Could not obtain transaction-synchronized 问题)