总结Hibernate(一)
2016-05-16 19:54
218 查看
Hibernate:持久层框架
添加环境:
jar包
配置文件:
主配置:hibernate.cfg.xml
映射配置:xxx.hbm.xml
使用Hibernate实现CRUD操作:
//准备:
Configuration cfg=new Configuration().configure();
SessionFactory sessionFactory=cfg.buildSessionFactory();
//模板代码:
Session session=sessionFactory.openSession();
Transaction tx=null;
try{
tx=session.openTransaction();
//操作
tx.commit();
}catch(Exception e){
tx.rollback();
}finally{
session.close();
}
//操作
Session中的方法:
save(Object)
update(Object)
delete(Object)
get(Class,id)
createQuery(hql)
主配置文件:
数据库信息
方言、驱动、url、username、password
导入配置文件
<mapping resource=" "/>
其他配置
show_sql=true
hbm2ddl.auto=update
映射配置:
映射基础:
1.要有无参的构造方法
2.要有主键
3.要有get、set方法
映射普通属性
映射主键
添加环境:
jar包
配置文件:
主配置:hibernate.cfg.xml
映射配置:xxx.hbm.xml
使用Hibernate实现CRUD操作:
//准备:
Configuration cfg=new Configuration().configure();
SessionFactory sessionFactory=cfg.buildSessionFactory();
//模板代码:
Session session=sessionFactory.openSession();
Transaction tx=null;
try{
tx=session.openTransaction();
//操作
tx.commit();
}catch(Exception e){
tx.rollback();
}finally{
session.close();
}
//操作
Session中的方法:
save(Object)
update(Object)
delete(Object)
get(Class,id)
createQuery(hql)
主配置文件:
数据库信息
方言、驱动、url、username、password
导入配置文件
<mapping resource=" "/>
其他配置
show_sql=true
hbm2ddl.auto=update
映射配置:
映射基础:
1.要有无参的构造方法
2.要有主键
3.要有get、set方法
映射普通属性
映射主键
相关文章推荐
- 2016年5月可用的KMS服务器
- [BZOJ 4436][Cerc2015]Kernel Knights
- CSS 3 组合选择器
- module作为多个APP的业务包依赖导入studio不能提交SVN不能与源文件的同步修改内容的问题
- 开灯问题
- 远程摄像头软件mjpg-streamer使用指南
- ANDROID STUDIO集成GENYMOTION模拟器
- 【GDOI2016Day1】第二题 最长公共子串
- leetcode.162. Find Peak Element
- vimtutor中文版
- Struts上传文件fileupload
- 推荐系统基础之一-简介
- JavaCAS操作
- [dp+数论]bzoj1004
- 学习心得 六 修改
- 数据库索引
- Sublime Text 3 绝对神器
- Android中EditText中的InputType
- hdoj 2055 An easy problem (单个字符)
- CSS 3 伪元素选择器