java - How does bitwise_and work in Postgres 9.4 and Hibernate 5 -


we using postgresql 9.4, , hibernate 5.1 seems latest versions. know postgres 9.5 out, 9.4 doesn't seem old. use jpa hibernate 5.1 , create hql queries.

we have field in database bigint. bitmask us, stored integer. in java code, works great, when want check bitmasks, doesn't work.

error org.hibernate.engine.jdbc.spi.sqlexceptionhelper -  error: function bitwise_and(bigint, integer) not exist hint: no function matches given name , argument types.  might need add explicit type casts. 

i'm looking @ generated hibernate sql , can see have like:

bitwise_and(mytable_.actionbitmask, 2)>0  

so, i'd raw sql work first, , can tweak hql query make work also.

now, have searched google, , results come with: - can't done in hql, have use regular sql of these old comments, , since postgres 9.4, hibernate 5.1, i'm thinking surely can figure out examples.

unfortunately, postgres 9.4 bit operations don't show bitwise_and @ all, documentation sucks there.

should convert decimals/longs binaries of same length in sql string before execute hql?

any appreciated. thanks!

based on saw on internet , various google searches, there may take standard class 'postgresqldialect' , extended our own class:

public class mypostgresqldialect extends postgresqldialect 

we added code in here created special 'bitwise_and' function.

i had change database dialect in spring application context file, , re-ran hql query.

i didn't know case, because until weren't doing bitwise checks @ all. did not know had dialect extension until recently.

but solved our problem. thanks!


Comments