Hibernate的HQL基础 HibernateMySQL
程序员文章站
2022-05-07 19:27:25
...
a)大小写敏感问题:只对类和属性区分大小写。 b)关联: (inner) join left (outer) join right (outer) join full (outer) join with from Emp e join Dept d on e.deptId = d.id with e.name is not null fetch:把所关联的对象一同取出来 from Emp e join fetch e.dept select e.dept from Emp e from Emp e where e.dept.company.group.address.city is not null 1) select子句: select u.name, u.score from User u; select new User(u.name, u.score) from User u; select new List(u.name, u.score) from User u; select new Map(u.name as uname, u.score as uscore) from User u; 2)命名参数 形式 —— “:paraname” query.setParameter("paraname", "z"); 3)where子句 a、比较运算:可以比较对象 from Emp e1, Emp e2 where e1.dept = e2.dept; b)内置class属性 from Product p where p.class = Book; 相当于 from Book; 4)内置函数 a)字符串: 连接 ‘a’ || ‘b’ upper(s)、lower(s) trim(s) length(s) substring(s, start, len) b)日期函数: 取当前日期(时间):current_date(),current_time(),current_timestamp() 处理日期字段的:year(date_field),month(date_field),day(date_field) ,hour(),minute(),second() from Order o whrere year(o.createDate) = 2010 c)类型转换函数: str(age) str(createDate) cast(age as string) cast('2011-01-05' as date) '2011-01-05 12:10:23' d)条件分支——“if else” case category when 1 then 'Book' when 2 then 'DVD' else 'unknown' end case when money_val <= 20000 then 'deptManager' when money_val >= 20000 and money_val <= 50000 then 'fz' else 'topleader' end 5)子查询(嵌套查询) from Cat fatcat where fatcat.weight > (select avg(weight) from Cat); 6)注意:某些底层数据库不支持某些特殊的功能。 如 having中聚集函数(sum)在某些数据库 (如MySql)是不支持的。 from Emp e group by e.age having avg(e.age) < 60
上一篇: struts2 开发模式