gpt4 book ai didi

java - JPA 中的 @OneToMany 关系且 IS NOT EMPTY

转载 作者:行者123 更新时间:2023-12-01 13:20:10 28 4
gpt4 key购买 nike

我需要选择所有具有与其关联的工作流程任务的文章。我尝试使用以下 JPA 查询(带有 Play! Framework、JPA、Hibernate 的 icm):

 List<Article> list = find("site.app=? AND workflowSteps IS NOT EMPTY ORDER BY pubDate DESC", app).fetch();

但这会产生傻瓜错误:

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]

实体的相关代码是:

@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;
}

这样可能吗?如果可以,我做错了什么?

最佳答案

您必须将实体映射到各自的表并添加 @Table 注释:

@Entity
@Table(name="ARTICLE")
public class Article extends ....

.....

@Entity
@Table(name="WORKFLOW_STEP")
public class WorkflowStep extends ....

关于java - JPA 中的 @OneToMany 关系且 IS NOT EMPTY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22098183/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com