我有一個實體:爲什麼我的實體表映射在JPA Hibernate中?
@Entity(name = "target_group")
public class TargetGroup extends AbstractEntity {
private String name;
private String description;
@ManyToMany(fetch = FetchType.LAZY)
private List<Customer> customers = new ArrayList<>();
getter.setter...
}
而且我有一個代碼,以獲得有關與stableId
組列表(這是在抽象類):
public TargetGroup getTargetGroupByStableId(String stableId) {
TargetGroup tg = null;
try {
Query q = em.createQuery("SELECT tg FROM TargetGroup tg WHERE tg.stableId = :stableId");
q.setParameter("stableId", stableId);
tg = (TargetGroup) q.getSingleResult();
logger.debug("TargetGroup reached: "+tg.generalInfo());
} catch(Exception e) {
logger.error("Error in getting TargetGroup by stableId:"+stableId,e);
throw e;
}
return tg;
}
而且我得到此錯誤:
SEVERE: Error in getting TargetGroup by stableId:51a7b93f-a342-44ec-9849-cd1688102f65
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: TargetGroup is not mapped [SELECT tg FROM TargetGroup tg WHERE tg.stableId = :stableId]
這是爲什麼?我錯了什麼,在代碼中應該更改什麼?謝謝!