SQL语法有什么问题?

时间:2015-09-04 10:49:21

标签: java jpa eclipselink jpql

嘿,伙计们我遇到了JPA查询的问题。

这里是Code-Snippet:

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

它只是说&#34; select语句必须有一个FROM子句。&#34;,但在我看来有一个。

1 个答案:

答案 0 :(得分:2)

我认为你应该尝试:

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

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