开发者

Hibernate createQuery remove() in WHERE condition

let's say I have entity Person.

When I try to use with hibernate createQuery, it remove ( ) in where condition. Example:

Query query = session.createQuery("FROM Person WHERE name=? OR (id=? AND active=?)");
query.setParameter(1, "Test");
query.setParameter(2, 1);
que开发者_JS百科ry.setParameter(3, 1);
// and so on

When I open debug sql output in hibernate, it produces

where person0_.`name`=? or person0_.`id`=? and person0_.`active`=?

Cause I put () inside the where condition, the output should be

where person0_.`name`=? or (person0_.`id`=? and person0_.`active`=?)

why the () in where condition is removed? or am I miss something?

Thanks


AND has a higher precedence than OR in SQL so the two statements are equivalent. Hibernate removes the unnecessary parentheses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜