我正在将Hql Query转换为jpql但是错误非法使用LONG数据类型
String jpqlQuery="select entity "+
"FROM Entity entity "+
"WHERE CAST(SUBSTRING(entity.nameId,2,12) AS long) >CAST( :String1 AS long) "+
"AND CAST(SUBSTRING(entity.nameId,2,12) AS long)<= CAST( :String2 AS long) ";
所以任何人都可以知道如何在jpql中为上述查询进行转换吗?
答案 0 :(得分:0)
decimal
或NUMERIC
代替long
:CAST(SUBSTRING(entity.nameId, 2, 12) AS DECIMAL(2,12))
例如:
String jpqlQuery = "select entity "+
"FROM Entity entity "+
"WHERE CAST(SUBSTRING(entity.nameId, 2, 12) AS DECIMAL(2,12)) > value1 "+
"AND CAST(SUBSTRING(entity.nameId, 2, 12) AS DECIMAL(2,12)) <= value2 ";
Query query = session.createQuery(jpqlQuery);
query.setParametter("value1", Long.valueOf(value1));
query.setParametter("value2", Long.valueOf(value2));