[英]A @OneToMany relationship in JPA and IS NOT EMPTY
I need to select all articles who do have work flow tasks associated with them. 我需要选择所有具有相关工作流程任务的文章。 I tried to use the following JPA query (icm with the Play! Framework, JPA, Hibernate):
我尝试使用以下JPA查询(带有Play!Framework,JPA,Hibernate的icm):
List<Article> list = find("site.app=? AND workflowSteps IS NOT EMPTY ORDER BY pubDate DESC", app).fetch();
But this gives the fool wing error: 但这给出了傻瓜机翼错误:
IllegalArgumentException occured : org.hibernate.hql.ast.QuerySyntaxException: workflowStep is not mapped [from models.Article where site.app=? AND workflowSteps IS NOT EMPTY ORDER BY pubDate DESC]
The relevant code for the entities are: 实体的相关代码为:
@Entity
public class Article extends TemporalModel {
@OneToMany(mappedBy = "article", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
public List<WorkflowStep> workflowSteps;
}
@Entity
public class WorkflowStep extends TemporalModel {
public WorkflowStepType type;
@Required
@ManyToOne
@JoinColumn(name="article")
public Article article;
}
Is this possible this way, and if so, what am I doing wrong? 这样可能吗?如果是这样,我在做什么错?
You must map your entities to their respective tables and add @Table
annotations: 您必须将实体映射到它们各自的表并添加
@Table
批注:
@Entity
@Table(name="ARTICLE")
public class Article extends ....
.....
@Entity
@Table(name="WORKFLOW_STEP")
public class WorkflowStep extends ....
QuerySyntaxException:It seems your query class name is not correct. QuerySyntaxException:您的查询类名称似乎不正确。 In the HQL , you should use the java class name and property name of the mapped @Entity instead of the actual table name.
在HQL中,应该使用映射的@Entity的java类名和属性名,而不是实际的表名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.