您的位置:首页 > 其它

hibernate_API简介

2015-10-05 00:00 260 查看
摘要: hibernate_API简介

-- API简介

Configuration 配置
configure() 如果不指定名称,那么默认就是:hibernate.cfg.xml
configure(String resource) 指定名称
addResource(String resource) 导入一个指定位置的映射文件,和hibernate.cfg.xml中
的<mapping resource="cn/it/domain/User.hbm.xml"/>

addClass(Class clazz) 导入与指定类同一个包中的以类名为前缀,后缀为.hbm.xml的映射文件如:User.hbm.xml, addClass(User.class);//这样就将: User.hbm.xml映射文件导入进 来了。

buildSessionFactory()

SessionFactory Session工厂
openSession()
getCurrentSession()
close()

Session 很重要的一个对象
操作对象的方法
save(Object)
update(Object)
delete(Object)
查询的方法
createQuery(String) --> Query
createCriteria(Class)
管理事务的方法
beginTransaction() --> Transaction
getTransaction() --> Transaction 获取当前Session中关联的事务对象
其他的方法
...

Transaction 事务
commit()
rollback()

Query 查询
list() 查询一个结果集合。
uniqueResult() 查询一个唯一的结果,如果没有结果,则返回null,如果结果有 多个,就抛异常。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: