Question

I my project I am using hibernate (3.5.6) to interact with db.. I am using DetachedCriteria and projections API to form my general queries.

DetachedCriteria detachedCriteria = DetachedCriteria.forClass(<ClassName>.class,"rp");
detachedCriteria.setProjection(Projections.count("<field>"));
detachedCriteria.add(Restrictions.eq("<field>", field));
count = (Long) getHibernateTemplate().findByCriteria(detachedCriteria).get(0);

Now I want to perform 'bitwise and' operation over values.. I can use the same methods to perform this 'bitwise and' operation.. If not what is the best way to do this ?

Thanks in advance.

Was it helpful?

Solution

Figured out the solution myself..

Key thing is to extend the default 'Dialect' to you custom dialect and register your custom method for the bitwise and operation

public class MySQLDialect extends org.hibernate.dialect.MySQLDialect {
    public MySQLDialect() {
       super();
       registerFunction("bitwise_and", new MySQLBitwiseAndSQLFunction("bitwise_and", Hibernate.INTEGER));
   }
}

Here is the link with full explanation: https://forum.hibernate.org/viewtopic.php?t=940978

Cheers :)..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top