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,如果结果有 多个,就抛异常。
-- 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,如果结果有 多个,就抛异常。
相关文章推荐
- 创建sessionFactory
- hibernate的开发包的结构及hibernate的开发所需要的jar包
- hibernate入门简介,学习示意图
- hibernate映射文件详解:xxx.hbm.xml文件详解
- 查询—criteria
- xxx.hbm.xml文件详解(主键配置)
- 属性是集合的映射
- Balsamiq Mockups完全手册
- pom.xml报错的解决办法
- 安装Docker
- 下载Docker镜像
- 制作Docker镜像
- 华硕笔记本F80s解决声卡噪音问题
- arch 更新后,powerpill 报错 import pm2mp 问题
- 监控服务器:设置用户登录邮件提醒
- mysql悲观锁总结和实践
- mysql乐观锁总结和实践
- PHP下的session的生存周期
- linux安装weblogic
- 无损歌曲音乐转apple lossless