");//里面是SQL语句 SQLQuery sqlQuery = session.createSQLQuery(hqlBuffer.toString()); sqlQuery.addScalar("propertyName",Hibernate.STRING);//该propertyName是 ObjectVO实体的一个属性 sqlQuery.setResultTransformer(Transformers.aliasToBean(ObjectVO.class)); List list = sqlQuery.list(); return list;//此处list集合中存放的是ObjectVO对象 } });2).返回结果放到list中的: final String queryString = "";//sql语句 List resultList=getHibernateTemplate().executeFind(new HibernateCallback() { public List doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery sqlQuery = session.createSQLQuery(queryString); List list=sqlQuery.executeUpdate(); return list; } });3).无返回结果: final String queryString = "";//SQL语句 getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { SQLQuery sqlQuery = session.createSQLQuery(queryString); sqlQuery.executeUpdate(); return null; } }); 。
4. hibernate查询语言 1 .from 1.1单表查询 from eg.cat as cat.其中,cat只是一个别名,为了用其他子语句的时候书写简单 1.2多表查询 from eg.Cat,eg.Dog from eg.Cat as cat,eg.Dog as dog 2 join相关 (inner) join left (outer) join right (outer) join full join HQL同样对SQL中的这些特性支持 下面插播一个小话题,关于上边的那些特性,我一直都没怎么用,今天既然说到这里,就想 把上边的几个特性的用法说一下,也算对自己的一个补充: 假设有两个表:部门、员工,下面列举一些数据: 员工(Employee): ID Name DepNo 001 Jplateau 01 002 Jony 01 003 Camel 02 部门(Department): ID Name 01 研发部 02 营销部 在Hibernate中我们操纵的都是对象,所以我们操纵的是部门类和员工类 1).(inner) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee join Department as department on employee.DepNo= department.ID (注意到条件语句我用on 没有用where) 那么执行结果是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 2).left (outer) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee left join Department as department on employee.DepNo= department.ID 那么执行结果又该是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 003 Camel null null {就是说此时我要已第一个表的记录多少为准,第二个表中没有相应纪录的时候填充null} 3). right (outer) join select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee right join Department as department on employee.DepNo= department.ID 那么执行结果又该是什么呢? id1 name1 id2 name2 ++++++++++++++++++++++++++++++++++++++ 001 Jplateau 01 研发部 002 Jony 01 研发部 null null 02 营销部 {就是说此时我要已第二个表的记录多少为准,第一个表中没有相应纪录的时候填充null} 3 大小写敏感 4 。
select语句 就是要确定你要从查询中返回哪些对象或者哪些对象的属性 。写几个例子吧: select employee form Employee as employee select employee form Employee as employee where employee.Name like 'J%' select employee.Name form Employee as employee where employee.Name like 'J%' select employee.ID as id1,employee.Name as name1,department.ID as id2,department.Name as name2 from Employee as employee right join Department as department on employee.DepNo= department.ID select elements(employee.Name) from Employee as employee (不明白elements到底是做什么用的?望给于说明) 等等 5 。
数学函数 JDO目前好像还不支持此类特性 。avg( 。
), sum( 。), min( 。
), max( 。) count(*) count( 。
), count(distinct。), count(all 。
- 怎么写html网页
- 港澳通行证查询 港澳通行证查询进度微信
- 查询工商银行卡余额 查询工商银行卡余额需要下载什么
- js怎么写判断语句
- 电焊工证查询 电焊工证查询电话
- 2017巢湖市中考成绩查询时间及查询入口
- 邮寄包裹号查询 邮寄包裹号查询表
- 手机型号查询 手机型号查询官网
- 数据库中语句怎么写
- 山东会考成绩查询 山东会考成绩查询