博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
herbnate session.createSQLQuery(sql) 和 session.createQuery(sql)使用
阅读量:6253 次
发布时间:2019-06-22

本文共 3196 字,大约阅读时间需要 10 分钟。

public class DistributeDao implements Serializable{    private SessionFactory sessionFactory;          public Session getSession() {          return sessionFactory.getCurrentSession();      }        public SessionFactory getSessionFactory() {          return sessionFactory;      }        public void setSessionFactory(SessionFactory sessionFactory) {          this.sessionFactory = sessionFactory;      }          public Task getTask(Integer id) {        Session session = this.getSession();        Transaction tran = session.beginTransaction();        List
datas = session.createQuery("from TestMessage").list();//TestMessage是一个java类,这个类和某一个表对应! tran.commit(); return datas.get(id); } public void saveTask(Task task) { Session session = this.getSession(); Transaction tran = session.beginTransaction(); session.save(task); tran.commit(); } public List
findAllTask() { Session session = this.getSession(); Transaction tran = session.beginTransaction(); List
datas = session.createQuery("from Task").list(); tran.commit(); return datas; } public List
findAllFinishedTask() { Session session = this.getSession(); Transaction tran = session.beginTransaction(); List
datas = session.createQuery("from Task where state=2").list(); tran.commit(); return datas; } public List
findUserTaskFinish(String developName){ Session session = this.getSession(); Transaction tran = session.beginTransaction(); String sql="select * from task where task.taskid in (select taskteam.taskid from taskteam where taskteam.developName=\'" + developName + "\') and task.state=2"; List
datas = (List
)session.createSQLQuery(sql).addEntity(Task.class).list(); tran.commit(); return datas; } public List
findUserTaskNoParticipateTask(String developName){ Session session = this.getSession(); Transaction tran = session.beginTransaction(); String sql="select * from task where task.taskid not in (select taskteam.taskid from taskteam where developName=\'" + developName + "\')"; List
datas = (List
)session.createSQLQuery(sql).addEntity(Task.class).list();//必须有addEntity()方法,否则不能                                                           //返回具体的类型,其实返回的是Object tran.commit(); return datas; } public List
findUserTaskParticipating(String developName){ Session session = this.getSession(); Transaction tran = session.beginTransaction(); String sql="select * from task where task.taskid in (select taskteam.taskid from taskteam where developName=\'" + developName + "\') and task.state=1"; List
datas = (List
)session.createSQLQuery(sql).addEntity(Task.class).list(); tran.commit(); return datas; } public List
findTaskAllUser(int taskid){ Session session = this.getSession(); Transaction tran = session.beginTransaction(); String sql="select * from developingparty where developingparty.developName in (select taskteam.developingparty from taskteam where taskteam.taskid=" + taskid + ")"; List
datas = session.createSQLQuery(sql).addEntity(DevelopingParty.class).list(); tran.commit(); return datas; }}

转载地址:http://ogfsa.baihongyu.com/

你可能感兴趣的文章
Apache Spark源码走读之20 -- ShuffleMapTask计算结果的保存与读取
查看>>
Ext 4.2.1 教大家如何去规避ext-all和动态加载机制的优缺点
查看>>
异常处理汇总 ~ 修正果带着你的Code飞奔吧!
查看>>
jdbc
查看>>
百度地图需要的效果-有感
查看>>
查看 NPM、Yarn 全局安装的包
查看>>
[BZOJ 2140]稳定婚姻(强连通分量)
查看>>
人工智能工程师学习路线
查看>>
Nginx入门(2)反向代理和负载均衡
查看>>
MySQL库表状态查询
查看>>
【鲁班学院】干货分享!《面试必备之Mysql索引底层原理分析》
查看>>
第十一周项目0-是春哥啊
查看>>
poi做一个简单的EXCAL
查看>>
几种查询emacs帮助的办法
查看>>
Python_基础_(模块,time,random,os,sys,json,shelve,xml,序列化反序列化)
查看>>
异常:Project configuration is not up-to-date with pom.xml解决方案
查看>>
HDU2647 拓扑排序
查看>>
ThinkPHP/---微信支付PC流程
查看>>
JavaScript 05
查看>>
python 多线程编程之threading模块(Thread类)创建线程的三种方法
查看>>