在hibernate3中,使用了c3p0连接池,尝试了多种办法取得connection对象,以下两种可以使用。
-
- Connection conn;
-
-
- conn = session.connection();
-
-
-
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor)new Configuration().configure().buildSessionFactory();
- conn = sessionFactory.getConnectionProvider().getConnection();
-
-
- ConnectionProvider cp =((SessionFactoryImplementor)sessionFactory).getConnectionProvider();
- cp.getConnection();
Connection conn;
// 方法1:hibernate4中将要废弃这个方法
conn = session.connection();
// 方法2:这个方法也可以用,速度稍慢
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor)new Configuration().configure().buildSessionFactory();
conn = sessionFactory.getConnectionProvider().getConnection();
//方法:3
ConnectionProvider cp =((SessionFactoryImplementor)sessionFactory).getConnectionProvider();
cp.getConnection();
2012/06/25
http://zhidao.baidu.com/question/170727565.html
按hibernate的计划,4.0开始将除去Session.connection()这个方法,所以还是最好不要使用它了。
官方的替代方法是用Session.doWork();
如:
- getSession().doWork(
-
new Work() {
-
public void execute(Connection connection) {
-
-
- }
- }
- );
分享到:
相关推荐
使用hibernate封装方法,显现使用一个dao,service,impl来关联两个表的操作,实现,增删改查基本操作
Hibernate基本数据操作方法 java struts hibernate
Hibernate操作数据库的方法.doc
hibernate中文API,hibernate中文参考手册,hibernate API
hibernate_中文乱码hibernate_中文乱码hibernate_中文乱码hibernate_中文乱码hibernate_中文乱码hibernate_中文乱码
#hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider #hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider #hibernate....
hibernate中文文档hibernate中文文档hibernate中文文档hibernate中文文档hibernate中文文档
Hibernate 中文文档Hibernate 中文文档Hibernate 中文文档Hibernate 中文文档
hibernate中session对象的状态详解
hibernate常用方法集合
hibernate中session的管理描述。 hibernate中session的管理描述。
Hibernate中Example的用法
注意:在Hibernate3中,第二个要求并非是Hibernate强制必须的。但最好这样做。 你不能使用一个IdentifierGenerator产生组合关键字。一个应用程序必须分配它自己的标识符。 使用<composite-id> 标签(并且内嵌元素...
hibernate中的generator的生成方式 hibernate中的generator的生成方式
hibernate中英文API文档 hibernate中英文API文档 hibernate中英文API文档hibernate中英文API文档 hibernate中英文API文档
Hibernate 中文手册 3.2.pdf
Hibernate开发者指南,包括HIBERNATE - Relational Persistence for Idiomatic Java.pdf,Hibernate Getting Started Guide.pdf,Hibernate Developer Guide.pdf,Hibernate 中文API文档.chm,Hibernate3.2.chm。