SSH整合之Hibernate4遇见Spring3——Http500org.springframework.orm.hibernate4.SessionHolder cannot be cast to
2017-03-11 17:06
453 查看
问题:
今天尝试整对Struts2+Spring+Hibernate三大框架进行整合时,发现了下面这个错误
原因:Hibernate 4与Spring 3有冲突
今天尝试整对Struts2+Spring+Hibernate三大框架进行整合时,发现了下面这个错误
HTTP Status 500 - org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder type Exception report message org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.ClassCastException: org.springframework.orm.hibernate4.SessionHolder cannot be cast to org.springframework.orm.hibernate3.SessionHolder org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:289) org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:235) org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457) org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393) org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
原因:Hibernate 4与Spring 3有冲突
import org.hibernate.Session; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** * 商品管理的DAO类 * @author ZSQ * */ public class ProductDao extends HibernateDaoSupport{ /** * DAO中保存商品的save方法 */ public void save(Product product){ System.out.println("Dao中的save方法执行了"); //this.getHibernateTemplate().save(product); //此为hibernate 3的hibernate模板保存方法,
//hibernate 4已经抛弃了,改成下面的方式 Session session = getSessionFactory().getCurrentSession(); session.save(product); } }
/* * 分页查询用户 */ @SuppressWarnings("unchecked") public List<User> findByPage(int begin, int pageSize) { DetachedCriteria criteria = DetachedCriteria.forClass(User.class); Session session = getSessionFactory().getCurrentSession(); List<User> list = (List<User>) criteria.getExecutableCriteria(session) .setFirstResult(begin).setMaxResults(pageSize).list();
//Hibernate4抛弃以下用法了,所以下面这行代码改为上面三行的代码 // List<User> list = // this.getHibernateTemplate().findByCriteria(criteria,begin,pageSize); return list; }
相关文章推荐
- Struts+Spring+Hibernate--SSH整合实例
- MyEclipse整合SSH(Struts+Spring+Hibernate)简单登录范例(二)
- Struts+Spring+Hibernate--SSH整合实例
- Struts2.2.1 Spring3.0.4 Hibernate3.6 整合 附加springside3 [ss2h ss3 ss2hss3 ssh2 s2sh]
- Struts Spring Hibernate (SSH) 整合实例
- Struts+Spring+Hibernate--SSH整合实例
- Struts+Spring+Hibernate/SSH整合开发详细一
- 使用MyEclipse集成SSH整合Spring和Hibernate
- Spring+Hibernate如何配置数据源(Struts Spring Hibernate (SSH) 整合实例)
- ssh 整合 struts + spring + hibernate
- MyEclipse整合SSH(Struts+Spring+Hibernate)简单登录范例(一)
- Struts+Spring+Hibernate--SSH整合实例
- Struts Spring Hibernate (SSH) 整合实例
- Struts+Spring+Hibernate--SSH整合实例
- Struts Spring Hibernate (SSH) 整合实例
- 《细说如何整合spring+hibernate +jsf》全文下载地址为:http://download.csdn.net/source/927154
- Struts+Spring+Hibernate--SSH整合实例
- SSH学习笔记之关于struts-spring-hibernate整合配置问
- (转载)Struts Spring Hibernate (SSH) 整合实例
- Struts+Spring+Hibernate,SSH整合实例