Hibernate核心类和接口
Configuraion类
(1)管理hibernate的配置信息
(2)读取加载hibernate.cfg.xml配置文件中指定连接数据库的驱动、用户名、密码、url
(3)管理( *.hbm.xml)对象关系文件


hibernate.cfg.xml文件
(1)hibernate核心文件,用于指定各个参数,默认放在src目录下
(2)指定连接数据库的驱动、用户名、密码、url
(3)指定对象关系映射文件的位置

注:也可以使用hibernate.properties文件来替代该文件(推荐使用
   hibernate.cfg.xml)

对象关系映射文件(*.hbm.xml)//建立表和类的映射关系

SessionFactory接口
1、缓存sql语句和某些数据
2、属于重量级的类(吃内存),用单例模式保证一个应用中只需要一个SessionFactory实例
3、获取 Session的两个方法 openSession()和getCurrentSession()的区别
 (1)openSession()是获取一个新的session
  (2)getCurrentSession()获取和当前线程绑定的session,换言之,在同一个线程中,我们获取的session是同一session,这样可以利于事务控制
 (3)在hibernate.cfg.xml中配置使用getCurrentSession()
    <!-- 配置可以使用getCurrentSession() -->
    <property name="current_session_context_class">thread</property>
 (4)通过getCurrentSession()获取的session在事务提交后会自动关闭,通过openSession()获取的session则必须手动关闭
 (5)通过getCurrentSession()获取的sesssion,进行查询需要事务提交

Session接口//Session一个实例代表与数据库的一次操作(可以是crud组合)

 posted on 2012-12-10 20:30  Chenyong Liu  阅读(341)  评论(0编辑  收藏  举报