SQL 语法有什么问题?

Whats wrong with the SQL Syntax?

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

这里是代码片段:

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

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

    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

上面写的是"A select statement must have a FROM Clause.",但我认为是有的

我认为你应该试试:

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

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