Varchar to int typecasting in JPA 1.9

这一生的挚爱 提交于 2019-12-24 09:14:13

问题


I want to convert varchar to int in jpql. The field is varchar, but all the data will be in integer format only. My JPA library version is 1.9

I already used CAST and CONVERT methods, but it did not working.

My query is:

select SUM(Cast(model.wagonsRequired as INT)) from IptRailcargolines model where model.iptRailwayindent.id=7

or

select SUM(CONVERT(INT, model.wagonsRequired)) from IptRailcargolines model where model.iptRailwayindent.id=7

and my java console error is:

Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0 (Build b40-rc (03/21/2007))): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Syntax error parsing the query [select SUM(FUNCTION(CONVERT(INT, model.wagonsRequired))) from IptRailcargolines model where model.iptRailwayindent.id=:headId], line 1, column 20: unexpected token [(].
Internal Exception: line 1:20: unexpected token: (

Please help me to resolve the issue.

Thankyou for your reply...

I am using MyEclipse IDE. So, may be internally it will use the Eclipselink. Can you please tell me where can i found my EclipseLink version? and how can i use FUNC / FUNCTION method in my JPA query. (I am using SQLSERVER 2008.)

I think i found the eclipseLink version in my myeclipse. Windows > Preference > JPA

The version is 1.0

Please tell me the solution.


回答1:


CAST and CONVERT are not part of JPA (1.0 or 2.0, and there is no 1.9).

You seem to be using EclipseLink, but there is no 1.9 version either. These functions are supported in EclipseLink 2.4, previously (2.3) you could us the FUNC operator to call a database function, or use a native SQL query.



来源:https://stackoverflow.com/questions/13627276/varchar-to-int-typecasting-in-jpa-1-9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!