【问题标题】:Whats wrong with the SQL Syntax?SQL 语法有什么问题?
【发布时间】:2015-11-30 12:07:02
【问题描述】:

大家好,我遇到了 JPA 查询问题。

这里是代码片段:

TypedQuery<ViVertragDl> q = entityManager.createQuery("select * from ViVertragDl c where c.id = " + editContract.getId(), ViVertragDl.class);
List<ViVertragDl> jpaContractDls = q.getResultList();

在 SOAP-UI 中测试后,Glassfish 日志会抛出此错误:

    Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [select * from ViVertragDl c where c.id = 51]. 
[28, 28] A select statement must have a FROM clause.
[7, 7] The left expression is missing from the arithmetic expression.
[9, 27] The right expression is not an arithmetic 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)
    ... 91 more

它只是说“一个选择语句必须有一个 FROM 子句。”但我认为有一个。

【问题讨论】:

  • 好的,我自己修好了。应该有“c”而不是“*”通配符似乎在 JPQL 中不起作用
  • “好像不行”? JPQL 有一个定义的语法。这不是猜测。 www.datanucleus.org/products/accessplatform_4_2/jpa/jpql.html

标签: java jpa eclipselink jpql


【解决方案1】:

我觉得你应该试试:

select c from ViVertragDl c where c.id = " + editContract.getId()

http://www.objectdb.com/java/jpa/query/jpql/select

【讨论】:

  • 感谢您在一分钟前修复了它。
  • @patrick 我很尊重 objectdb,看起来很有趣的环境。您认为这种集成 objectDB +JPA 实现的经验可以扩展到“经典”JPA 环境吗?您是否在繁重的现实世界项目中使用 objectdb?
  • @Jacek Cz 其实我还是一名学生,并使用该网站作为正确使用 Java Persistence API 的参考。
  • @Patrick 好的,oodbd 似乎在设计和教育水平上都非常出色。有几次我考虑将其用于商业用途,但许可证(在某种程度上对商业不友好)并且没有关于硬使用的信息阻止了这个项目。
  • @Patrick。几天前:您使用 objectdb 文档是正确的。它设计得很好,格式很好(在谷歌中很高)。我也使用(一般意义上 - 当有错误去特定的提供者,即 Eclipse)
猜你喜欢
  • 2016-04-11
  • 1970-01-01
  • 2011-02-20
  • 2012-07-07
  • 2012-05-02
  • 2020-06-27
  • 1970-01-01
  • 1970-01-01
  • 2012-01-14
相关资源
最近更新 更多