我在 JPA 中面临一个关于多对一关系的问题。我现在遇到的问题是使用 where 子句获取数据。
Skills
班级:
@Id
private long skillsID;
@Basic
private String longDescription;
@Basic
private String shortDescription;
@Basic
private String colOrder;
@Basic
private String isActive;
@Basic
private String changeDate;
@ManyToOne(fetch=FetchType.EAGER)
private Category category;
第二个实体是:
Category
班级:
@Id
private long categoryID;
@Basic
private String name;
@Basic
private String colOrder;
@Basic
private String isActive;
@Basic
private String changedDate;
@OneToMany(mappedBy = "category")
private Collection<Skills> skills;
所以在 JPA 中,当我执行以下代码时,它会抛出异常,例如:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [SELECT s.longDescription from Skills s, Category c where s.categoryID = c.categoryID].
[57, 69] The state field path 's.categoryID' cannot be resolved to a valid type.
JPA代码是:
Query q = em .createQuery("SELECT s.longDescription from Skills s, Category c "+
"where s.categoryID = c.categoryID");
那么,如何根据外键获取Skills
数据Category
?