开发者

Hibernate createQuery remove() in WHERE condition

开发者 https://www.devze.com 2023-03-09 21:19 出处:网络
let\'s say I have entity Person. When I try to use with hibernate createQuery, it remove ( ) in where condition. Example:

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

精彩评论

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