由于这个错误,我对 JPA 和 Hibernate 感到非常困惑。
这是堆栈异常
2012-08-07 03:55:04,277 ERROR [org.hibernate.hql.PARSER] (HDScanner) Path expected for join!
2012-08-07 03:55:04,299 ERROR [org.hibernate.impl.SessionFactoryImpl] (HDScanner) Error in named query: getTotalCallReportsFromQuarter
org.hibernate.QueryException: Unable to resolve path [care.quarter], unexpected token [care] [SELECT count(noOfCallReports) FROM com.business.model.base.CareCallReport JOIN Relationships with CareCallReport.clientAccountNo=Relationships.clientAccountNo where UID = :UID and care.quarter = :quarter and care.year = :year]
这是我计划加入的两个实体:
CareCallReport.java
@Entity
@Table(name = "CARE_CALLREPORT")
public class ICareCallReport implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ClientAccountNo", nullable = false, length = 7)
private String clientAccountNo;
@Column(name = "NoOfCallReports", nullable = false, length = 11)
private int noOfCallReports;
@Column(name = "Quarter", nullable = false, length = 11)
private int quarter;
@Column(name = "QtrYear", nullable = false, length = 4)
private int year;
... Getters and Setters
和另一个实体
ITRelationships.java
@Entity
@Table(name = "IT_RELATIONSHIPS")
public class ITRelationships implements Serializable {
@Id
@Column(name = "ClientID",nullable = false, length = 7)
private String clientID;
@Column(name = "ClientAccountNo", nullable = false, length = 7)
private String clientAccountNo;
@Id
@Column(name = "UID", nullable = false, length = 6)
private String UID;
@Column(name = "Quarter", nullable = false, length = 11)
private int quarter;
@Column(name = "QtrYear", nullable = false, length = 4)
private int year;
Getters and Setters
我写的 JQL 方法是这样的:
<access>FIELD</access>
<named-query name="getTotalCallReportsFromQuarter">
<query>
<![CDATA[
SELECT count(noOfCallReports)
FROM CareCallReport JOIN ITRelationships
with CareCallReport.clientAccountNo = ITRelationships.clientAccountNo
where UID = :uid
and care.quarter = :quarter
and care.year = :year
]]>
</query>
</named-query>
我做错了什么?这是我第一次接触 JPA。