简体   繁体   English

需要在JPA2中使用按位“&”运算符

[英]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 我需要在JPA2中转换以下条件,但是发现没有替代方法可以应用没有JDBC参数的用SQL表示的约束

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

I tried using NativeQuery like the below sinppet where value is the parameter passing to the method:- 我尝试使用NativeQuery像下面的sinppet一样,其中value是传递给方法的参数:-

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 “ java.lang.ClassCastException:[Ljava.lang.Object;无法转换为com.pkg.userDefClass java.lang.RuntimeException

query.getResultList() is passing list of objects but not list of userdefClass objects. query.getResultList()正在传递对象列表,但不传递userdefClass对象列表。

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. 我也尝试使用类型查询,但是它抛出SQL Grammer Exception。我猜它没有解析SQL字符串中按位的'&'运算符。

Please help. 请帮忙。

请尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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