首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不在Eclipselink中工作的函数和运算符

问不在Eclipselink中工作的函数和运算符
EN

Stack Overflow用户
提问于 2014-10-08 21:01:40
回答 3查看 3.9K关注 0票数 8

我有这个问题,替换函数无法使用eclipselink版本2.5.2。

这是我的代码:

代码语言:javascript
复制
String sSql = " SELECT e FROM br.com.megasoft.protocolo.entity.Assunto e  WHERE  ( REPLACE(REPLACE(REPLACE( UPPER(e.titulo), '/', ''), '-', ''), '.', '') LIKE  UPPER('A') )";
TypedQuery<?> query = getEntityManager().createQuery(sSql, Class.forName(this.tabela));

第二个参数的值为:class br.com.megasoft.protocolo.entity.Assunto

它规定了这一例外:

代码语言:javascript
复制
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [ FROM br.com.megasoft.protocolo.entity.Assunto e  WHERE  ( REPLACE(REPLACE(REPLACE( UPPER(e.titulo), '/', ''), '-', ''), '.', '') LIKE  UPPER( :valorPesq10) ) ]. 
[54, 150] The expression is not a valid conditional expression.
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:334)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:116)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:102)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1603)
    ... 50 more

当我使用Hibernate时,它完全可以工作。

当我运行简单的SQL时,没有替换,它可以正常工作。

Obs: Eclipselink 2.5.2正在使用JPA2.1。我用的是Tomcat8,Eclipse开普勒。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-10-09 12:33:01

我找到了解决办法,谢谢你们提供的有用信息。

sql必须是这样的:

代码语言:javascript
复制
SELECT e FROM br.com.megasoft.protocolo.entity.Assunto e  WHERE  FUNCTION('REPLACE',  e.titulo, '/', '') LIKE  UPPER('A')

这样,我将使用在JPA2.1规范中定义的函数。

票数 11
EN

Stack Overflow用户

发布于 2014-10-08 23:22:52

我已经在规范和这个甲骨文页面(fun)中搜索过了,没有任何JPQL函数的替换。

我相信这是一个Hibernate函数:http://lkumarjain.blogspot.com.br/2013/07/compare-string-by-removing-white-chars.html

换句话说,替换属于HQL,而不是JPQL。

票数 3
EN

Stack Overflow用户

发布于 2014-10-09 06:29:34

JPA2.1具有JPQL "FUNCTION“,它允许在JPQL语句中使用SQL函数。您使用的不是JPQL,因为它是对规范的简单回顾,或者JPA实现的文档会告诉您

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26266384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档