Hibernate的Query和Session对象的示例
来源:互联网 发布:哥哥帅体验知乎 编辑:程序博客网 时间:2024/05/21 10:17
//将合法登陆员工封装在对象中并传回
public Staff getStaff(String staff_id)throws HibernateException{
Session session=null;
Transaction t=null;
Staff s;
try{
session=HibernateSessionFactory.getSession();
t=session.beginTransaction();
Query query=session.createQuery("from Staff where staff_id=? or staff_id=?");
query.setString(0,staff_id.trim());
query.setString(1,staff_id.trim());
s=(Staff)query.uniqueResult();
query=null;
t.commit();
t=null;
}catch(HibernateException e){
throw e;
}finally{
if(t!=null){
t.rollback();
}
HibernateSessionFactory.closeSession();
}
return s;
public Staff getStaff(String staff_id)throws HibernateException{
Session session=null;
Transaction t=null;
Staff s;
try{
session=HibernateSessionFactory.getSession();
t=session.beginTransaction();
Query query=session.createQuery("from Staff where staff_id=? or staff_id=?");
query.setString(0,staff_id.trim());
query.setString(1,staff_id.trim());
s=(Staff)query.uniqueResult();
query=null;
t.commit();
t=null;
}catch(HibernateException e){
throw e;
}finally{
if(t!=null){
t.rollback();
}
HibernateSessionFactory.closeSession();
}
return s;
}
Query query=session.createQuery("from Staff where staff_id=? or staff_id=?");
query.setString(0,staff_id.trim());
query.setString(1,staff_id.trim());
0和1分别对应sql语句中的第一个和第二个?符号。
0 0
- Hibernate的Query和Session对象的示例
- hibernate的session对象
- Hibernate的学习总结(Query对象)
- Hibernate中Query对象的使用
- Hibernate学习笔记(3):session的get、load、delete方法和Query的简单使用
- Hibernate 里 SQL 和 HQL,Criteria Query 对Session Cache缓存使用的不同
- day24 ORM Hibernate常用的接口和类(Configuration, SessionFactory , Session, Transaction ,Query) hql
- Hibernate的5个核心接口:Session、SessionFactory、Transaction、Query和Configuration
- Hibernate对象的状态,session的clear()和evict()
- ThreadLocal管理和获取Hibernate的Session对象
- Hibernate中Query.list()和Query.iterator()的区别
- hibernate案例入门一query transaction criteria sessionfactory和session区别 get和load的区别 opensession 和 getcurre
- Hibernate 的查询语言 Criteria 和Query
- hibernate中query和sqlquery的区别
- Hibernate的Query接口和查询操作
- Hibernate的Query接口
- hibernate的Criteria Query
- Hibernate的Criteria Query
- py2exe将py打包成exe程序
- 成员函数重载运算符和友元函数重载运算符的比较
- 解析C++中不能重载为友元函数的四个运算符
- 运用smali自动注入技术分析android应用程序行为
- Android 判断 PendingIntent 是否存在
- Hibernate的Query和Session对象的示例
- R语言中的回归诊断
- 用到的命令
- WebView与JS、Ajax跨域问题
- STM32使用printf
- 2.UIImageView
- PDF添加水印
- checkbox的只能选中一个,div下checkbox的遍历
- android全磁盘加密