在JPA 1.9中将​​Varchar转换为int类型转换 [英] Varchar to int typecasting in JPA 1.9

查看:203
本文介绍了在JPA 1.9中将​​Varchar转换为int类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将varchar转换为jpql中的int.该字段是varchar,但是所有数据将仅采用整数格式.我的JPA库版本是1.9

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

我已经使用了CAST和CONVERT方法,但是没有用.

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

我的查询是:

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

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

我的Java控制台错误是:

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: (

请帮助我解决问题.

谢谢您的回复...

我正在使用MyEclipse IDE.因此,可能会在内部使用Eclipselink.您能告诉我在哪里可以找到我的EclipseLink版本吗?以及如何在JPA查询中使用FUNC/FUNCTION方法. (我正在使用SQLSERVER 2008.)

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.)

我认为我在myeclipse中找到了eclipseLink版本. Windows>首选项> JPA

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

版本为1.0

请告诉我解决方案.

推荐答案

CAST和CONVERT不属于JPA(1.0或2.0,并且没有1.9).

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

您似乎正在使用EclipseLink,但是也没有1.9版本. EclipseLink 2.4(以前的2.3版)支持这些函数,您可以使用FUNC运算符调用数据库函数,或使用本机SQL查询.

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.

这篇关于在JPA 1.9中将​​Varchar转换为int类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆