hibernate核心类和接口
2016-04-18 15:58
183 查看
Part 1 Configuration类
Part 2 SessionFactory接口
通过SessionFactory获取Session有两个方法:openSession()和getCurrentSession
1、openSession()是获取一个新的session
2、getCurrentSession()获取和当前线程绑定的session,换言之,在同一个线程中,我们获取的session是同一session,利于事务的控制。
3、如果使用getCurrentSession需要在hibernate.cfg.xml中配置。
<property name="current_session_context_class">thread</property>
Part 3 Session接口
Part 4 Transaction接口
Part 5 Query接口
在实际应用中,Query接口十分常用,有更为强大的查询能力,而get、load只能根据主键查询,所以Query十分必要,Query可防止sql注入
Part 6 Criteria接口
Criteria接口也可用于面向对象方式的查询,实际使用的并不多。
Part 2 SessionFactory接口
通过SessionFactory获取Session有两个方法:openSession()和getCurrentSession
1、openSession()是获取一个新的session
2、getCurrentSession()获取和当前线程绑定的session,换言之,在同一个线程中,我们获取的session是同一session,利于事务的控制。
3、如果使用getCurrentSession需要在hibernate.cfg.xml中配置。
<property name="current_session_context_class">thread</property>
Part 3 Session接口
Part 4 Transaction接口
Part 5 Query接口
在实际应用中,Query接口十分常用,有更为强大的查询能力,而get、load只能根据主键查询,所以Query十分必要,Query可防止sql注入
Part 6 Criteria接口
Criteria接口也可用于面向对象方式的查询,实际使用的并不多。
//id指的是映射对象的属性名称而不是表的字段名 Query query=session.createQuery("from Employee where id=100"); List<Employee> list=query.list(); for(Employee e:list){ System.out.println(e.getName()+""+e.getHiredate()); }
Criteria cri=session.createCriteria(Employee.class).add(Restrictions.like("name","Fritz%")).setMaxResult(2); List<Employee> list=cri.list();
相关文章推荐
- TCP协议的学习(六)滑动窗口 停止等待 退后N帧 选择重传
- C语言结构体的字节对齐原则
- SAP物料移动类型
- 我的前端之旅--SeaJs基础和spm编译工具运用[图文]
- 222222222222222
- 怎样度过人生的低潮期?
- mongodb入门很简单(3)
- post提交方式
- 在iOS中,使用icon front
- Android ImageSpan使TextView的图文居中对齐
- 梳理caffe代码python_layer(十五)
- PHP输出验证码图片不显示问题
- iOS平台配置OpenCV
- 监听socket初始化
- HDU2035 人见人爱A^B
- Vim E568:: duplicate cscope database not added 解决方法
- Android PopupWindow详解
- JavaScript的对象转为原始值
- 未配置TCP/IP,必须安装并启用网络适配器
- 发布企业版本ios app