`
dongguang1082
  • 浏览: 10202 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

hibernate中的session和connection的区别

阅读更多
   在需要连接数据库的时候,就用到了session

    1:session的创建
      session通常通过以下2中方式来创建
        A Session session=SessionFactory.openSession();
        第一种方法每次获得的都是一个新的session,
       B  Session session=SessionFacotry.getCurrentSession();:
         第二种方法得到的是当前环境中的session
        当session  commit的以后,在那session的时候就是一个新的 session
       C:openSession需要手动close,getcurrentSession在提交后自动的close;
      session和connection的主要区别在于
       session可以管理缓存和connectionn则不可以。Session是对connection的进 一 步的封装session非线程安全的的,必须关闭,通常session关闭,事务关闭。connection则是线程安全的
分享到:
评论

相关推荐

    hibernate中session对象的状态详解

    hibernate中session对象的状态详解

    Hibernate+中文文档

    3.4. Hibernate JDBC和连接(connection)属性 3.5. Hibernate缓存属性 3.6. Hibernate事务属性 3.7. 其他属性 3.8. Hibernate SQL方言 (hibernate.dialect) 3.9. Hibernate日志类别 3.10. JTA ...

    Hibernate开发jar包

    Hibernate开发jar包 5.07 ... <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider <!-- 映射配置文件 --> </session-factory> </hibernate-configuration>

    hibernate.properties

    #hibernate.connection.provider_class org.hibernate.connection.DriverManagerConnectionProvider #hibernate.connection.provider_class org.hibernate.connection.DatasourceConnectionProvider #hibernate....

    hibernate3.2中文文档(chm格式)

    3.4. Hibernate JDBC和连接(connection)属性 3.5. Hibernate缓存属性 3.6. Hibernate事务属性 3.7. 其他属性 3.8. Hibernate SQL方言 (hibernate.dialect) 3.9. Hibernate日志类别 3.10. JTA ...

    Hibernate中文详细学习文档

    11.1. Session和事务范围(transaction scope) 11.1.1. 操作单元(Unit of work) 11.1.2. 长对话 11.1.3. 关注对象标识(Considering object identity) 11.1.4. 常见问题 11.2. 数据库事务声明 11.2.1. 非托管...

    hibernate小程序源码

    "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> ...

    Hibernate 中文 html 帮助文档

    11.1. Session和事务范围(transaction scope) 11.1.1. 操作单元(Unit of work) 11.1.2. 长对话 11.1.3. 关注对象标识(Considering object identity) 11.1.4. 常见问题 11.2. 数据库事务声明 11.2.1. 非托管环境 ...

    HibernateAPI中文版.chm

    3.4. Hibernate JDBC和连接(connection)属性 3.5. Hibernate缓存属性 3.6. Hibernate事务属性 3.7. 其他属性 3.8. Hibernate SQL方言 (hibernate.dialect) 3.9. Hibernate日志类别 3.10. JTA ...

    Hibernate注解编程实例

    <!-- EJB注解编程 --> <hibernate-configuration> <session-factory> <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/test ... <property name="hibernate.connection.driver_cl

    Hibernate1

    import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.junit.Test; import cc.tukai.entity.Student; public class testHibernate { @Test ...

    Hibernate配置数据连接

    配置Hibernate使用c3p0或Proxool连接池(2008-01-13 17:15:54)转载标签: 杂谈 1.Hibernate默认连接池 <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//...

    hibernate配置

    创建持久化对象和映射文件 1.持久化对象创建 2.映射文件创建格式: <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" ...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    3.4. Hibernate JDBC和连接(connection)属性 3.5. Hibernate缓存属性 3.6. Hibernate事务属性 3.7. 其他属性 3.8. Hibernate SQL方言 (hibernate.dialect) 3.9. Hibernate日志类别 3.10. JTA ...

    hibernate 体系结构与配置 参考文档(html)

    Session和事务范围(transaction scope) 11.1.1. 操作单元(Unit of work) 11.1.2. 长对话 11.1.3. 关注对象标识(Considering object identity) 11.1.4. 常见问题 11.2. 数据库事务声明 11.2.1. 非托管环境 ...

    搞定J2EE:STRUTS+SPRING+HIBERNATE整合详解与典型案例 (1)

    12.2.3 Session(提供Connection) 12.3 使用Hibernate操作数据库的示例 12.3.1 创建数据库表 12.3.2 编写表对应的JavaBean 12.3.3 编写JavaBean对应的Xml 12.3.4 编写Hibernate的配置文件 12.3.5 编写并验证测试...

    Spring的JDBCTemplate

    第二、使用Hibernate Session的getConnection 获得JDBC Connection,然后进行纯JDBC API操作; 第三、选择把Spring的JDBCTemplate作为一种很不错的JDBC Utils来使用。 JDBCTemplate的使用很简单,只要在...

    Hibernate自动生成数据库表映射实体类

    Connection connection = session.connection(); try { DatabaseMetaData metaData = connection.getMetaData(); ResultSet result = metaData.getColumns(null, null, NameOfTable, null); String strInJava...

    搞定J2EE:STRUTS+SPRING+HIBERNATE整合详解与典型案例 (3)

    12.2.3 Session(提供Connection) 12.3 使用Hibernate操作数据库的示例 12.3.1 创建数据库表 12.3.2 编写表对应的JavaBean 12.3.3 编写JavaBean对应的Xml 12.3.4 编写Hibernate的配置文件 12.3.5 编写并验证测试...

    ssh(structs,spring,hibernate)框架中的上传下载

    CONTENT表字段上,在Spring中采用OracleLobHandler来处理Lob字段(包括Clob和Blob),由于在程序中不需要引用到oracle数据驱动程序的具体类且屏蔽了不同数据库处理Lob字段方法上的差别,从而撤除程序在多数据库移植...

Global site tag (gtag.js) - Google Analytics