jta | thread | managed | custom.Class
jta(java transection api):分布式进行对数据库服务器进行操作。
注意:tomcat服务器不支持,中介服务器可以
thread:在当前线程里取得数据库的连接.
其它两种很少用,
Configuration:
a)AnnotationConfiguration
b)进行配置信息管理
c)可以在configure方法中指定hibernate配置文件
d)只需关注一个方法.即:buildSessionFactory()
SessionFactory:
a)用来产生和管理session.
b)通常情况下每个应用只需要一个SessionFactory.
c)除非要访问多个数据库的情况下
d)关注两个方法:openSession() getCurrentSession
i.opSession()每次都是新的session,需要close
ii.getCurrentSession从上下文找,如果有,用旧的
1.用途.界定事务边界
2.事务提交自动close
对象的三种状态:
三种状态的区分:
a)有没有Id
b)数据库有没有ID
c)在内存中有没有(session缓存)
三种状态:
transient(瞬时状态):内存中一个对象,没ID,缓存中也没有
persistent(持久化状态):内存中有,缓存中有,数据库中有,有ID
detached(离线状态):内存中有,缓存中没有,数据库中有,有ID
transient:
Teacher t=new Teacher();
t.setName("zhangsan");
t.setTitle("teacher");
t.setDate(new Date());
persistent:
Session session=sf.getCurrentSession();
session.beginTransaction();
System.out.println(t.getId());
session.save(t);
detached:
session.getTransaction().commit();
System.out.println(t.getId());