简体   繁体   中英

Need to use bitwise“&” operator in JPA2

I need to convert the below condition in JPA2,but found there is no alternative to Apply a constraint expressed in SQL with no JDBC parameters

Restrictions.sqlRestriction("{alias}.col3& " + value + " = " + value);

I tried using NativeQuery like the below sinppet where value is the parameter passing to the method:-

String sqlString="select * from myTable where col1=3600 and col2=true and col3&"+value+"="+value;
        Query query=getSession().createNativeQuery(sqlString);
        List<userDefClass> results = new ArrayList<userDefClass>();
        results=(List<userDefClass>)query.getResultList();

For the above logic ,I am getting below error:-

"java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.pkg.userDefClass java.lang.RuntimeException

query.getResultList() is passing list of objects but not list of userdefClass objects.

ALso I tried using Typed Query but it is throwing SQL Grammer Exception.I guess its not parsing the bitwise '&' operator in the SQL String.

Please help.

请尝试这个:

query.setResultTransformer(new AliasToBeanResultTransformer(userDefClass.class));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM