How to use bitwise operators in HQL?

In HQL, how can I use bitwise operators? I want the resulting SQL query to look something like this:

SELECT RoleId, RoleName, RolePerms WHERE (RolePerms & @Parameter) = @Parameter 

However, by writing this HQL

 select from Role where (RolePerms & :param) = :param 

gives me this error: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: an exception of type "Antlr.Runtime.NoViableAltException" was thrown.

+3
source share
3 answers

I have found a solution to this. Writing HQL in this way works:

 select r from Role r where (r.Permissions & :param) > 0 
+4
source

In section 13.8 of the NHibernate documentation , HQL does not support these bitwise operators. You will need to revert to the original SQL (see Section 15).

0
source

According to NHibernate Jira, it looks like this should work with 2.1.0Beta2, https://nhibernate.jira.com/browse/NH-1192 .

0
source

Source: https://habr.com/ru/post/1339559/


All Articles