在HQL之间是否严格比较?

时间:2009-02-25 13:58:02

标签: java hibernate jpa hql

如果我用HQL编写

A between 5 and 10

相当于

A >= 5 and A <= 10

A > 5 and A < 10

或其他4种组合?

2 个答案:

答案 0 :(得分:40)

我没有在Hibernate文档中找到任何行为规范,但是HQL中的between运算符被转换为SQL中的between运算符,这是包含的。

因此,HQL中的between也是包容性的,即

A between 5 and 10

相当于

A >= 5 and A <= 10

答案 1 :(得分:3)

显然,对此存在一些困惑。自然语言会暗示它是独一无二的,但事实并非如此。实际上,其A> = 5且A <= 10。 由于已经给出了(并且已经删除)相互矛盾的答案,因此需要进一步澄清:(来自http://www.techonthenet.com/sql/between.php

Example #1 - Numbers

The following is an SQL statement that uses the BETWEEN function:

SELECT *
FROM suppliers
WHERE supplier_id between 5000 AND 5010;

This would return all rows where the supplier_id is between 5000 and 5010, inclusive. It is equivalent to the following SQL statement:

SELECT *
FROM suppliers
WHERE supplier_id >= 5000
AND supplier_id <= 5010;