JPQLException:状态字段路径&#t; id'无法解析为有效类型

时间:2014-05-26 10:40:05

标签: jpa eclipselink jpql

我正在使用eclipseLink并且提到了下面提到的查询。

Query q = entityManager.createQuery("SELECT t FROM "
                    + clazz.getName() + " t WHERE t.id = :id");
            q.setParameter("id", id);
            matchedEntity = (T) q.getSingleResult();

但有时我只会收到以下错误

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [SELECT t FROM com.mt.igg.entities.CitizenRequest t WHERE t.id = :id]. 
[57, 61] The state field path 't.id' cannot be resolved to a valid type.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    at com.sun.proxy.$Proxy94.createQuery(Unknown Source)

代码有时有效,有时我只会得到上述错误。 查询中字段的大小写与实体中的字段相同。

我正在使用tomcat服务器来部署项目

编辑:CitizenRequest实体:

@Entity
@Table(name = "CITIZEN_REQUEST")
@Multitenant
@TenantDiscriminatorColumn(name = "TENANT_ID", contextProperty = PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT)
public class CitizenRequest implements Serializable {

    // id of CitizenRequest
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;
    // Title of CitizenRequest
    @Column(name = "TITLE_ID")
    @NotNull
    private Integer title;

0 个答案:

没有答案