hibernate4.0 session.connection() 废弃解决,项目升级解决。
来源:互联网 发布:windows桌面图标没了 编辑:程序博客网 时间:2024/05/16 09:40
1,在hibernate4.0中移除了。session.connection(); ---><url>https://hibernate.onjira.com/browse/HHH-2603</url>
所以在使用hibernate操作离散型JDBC操作的时候,不能再使用这个方法。
解决方案:
1,hibernate4只是在接口Deprecate了这个interface,那么我们仍然可以SessionImpl得到
<code>
2,或者使用hibernate提供的解决方案在hibernate API中提到了替代方法---->http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/jdbc/Work.html
使用方法如下:
<code>
3,或者使用:
SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection()
所以在使用hibernate操作离散型JDBC操作的时候,不能再使用这个方法。
解决方案:
1,hibernate4只是在接口Deprecate了这个interface,那么我们仍然可以SessionImpl得到
<code>
public Connection getConnection() { try { if (connectionMethod == null) { // reflective lookup to bridge between Hibernate 3.x and 4.x connectionMethod = this.session.getClass().getMethod("connection"); } return (Connection) ReflectionUtils.invokeMethod(connectionMethod, this.session); } catch (NoSuchMethodException ex) { throw new IllegalStateException("Cannot find connection() method on Hibernate session", ex); } }</code>
2,或者使用hibernate提供的解决方案在hibernate API中提到了替代方法---->http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/jdbc/Work.html
使用方法如下:
<code>
session.doWork(new Work() {@Overridepublic void execute(Connection conn) throws SQLException {doSomeThingWithJdbc(conn);}}</code>
3,或者使用:
SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection()
来自类org.springframework.orm.hibernate4.SessionFactoryUtils
- hibernate4.0 session.connection() 废弃解决,项目升级解决。
- Hibernate4中buildSessionFactory方法废弃解决
- Hibernate4使用Session获取Connection返回ResultSet
- hibernate4.0以上使用Connection
- 升级Spring3.1RC2 和Hibernate4.0.0CR7遇到的一些问题及解决
- apache+tomcat解决session项目问题负载。
- Spring3 + Hibernate4 配置 No Session found for current thread问题的解决
- Jstl调用后台数据 解决Hibernate4:could not initialize proxy - no Session
- 关于struts+spring4+hibernate4整合是出现的No Session found for current thread解决
- 解决session 关闭问题 WARN - unclosed connection, forgot to call close() on your session?
- connection refused 解决
- 解决升级chrome后,访问https出现Your connection is not private
- Android中TextView控件的singleLine废弃解决
- 解决xcode4.6升级xcode5.0后,打开项目就崩溃现象问题
- Hibernate4解决MySql中文排序问题
- 解决 Lr[10061]Connection refused
- 解决PEAR connection problems问题
- Connection refused问题的解决
- 转 Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Android实现ListView异步加载图片
- 关于public, private 和 protected继承中对基类成员的访问
- SQL SEVER 之 T-SQL
- ORACLE varchar,varchar2,nvarchar,nvarchar2
- hibernate4.0 session.connection() 废弃解决,项目升级解决。
- -bash java command not found
- 深入探索ScrollWindow
- T_SQL 2008 语言基础学习笔记
- Android 通过软引用实现图片缓存,防止内存溢出
- Linux下java环境变量设置方法
- hdu2531 Catch him
- poj 3693 Maximum repetition substring
- java.lang.NoClassDefFoundError: org.apache.commons.lang.StringEscapeUtils