我想用JOIN和JPA。这是我的JPA查询:
SELECT o FROM Assessment AS o
INNER JOIN AssessmentText at
WHERE o = at.assessment
AND at.localeCode = :localeCode
从
Assessment
到AssessmentText
的关系是OneToMany
。当我执行此查询时,我得到:
org.apache.openjpa.persistence.ArgumentException:
Encountered "INNER JOIN AssessmentText at" at character 31,
but expected: [".", "FETCH", "INNER", "JOIN", "LEFT", <IDENTIFIER>].
我正在使用JPA实现:OpenJPA 2.2.1和MySQL数据库。
我为什么会犯这个错误,怎么解决?
最佳答案
假设您希望立即获取AssessmentText,则可以执行此操作(assument Assessment有一个名为AssessmentText的成员):
SELECT o FROM Assessment AS o LEFT JOIN FETCH o.assessmentText WHERE o.assessmentText.localeCode = :localeCode
关于java - JPA联接查询不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14121149/