java - 当我对自引用实体进行查询时出现 SQLException

标签 java jpa playframework playframework-2.0 ebean

我有一个根据此模式构建的实体:

@Entity
@Table(name = "participation_formation")
public class ParticipationFormation extends Model {

    @Id
    public int id;

    @OneToOne
    @JoinColumn(name = "id_formation")
    public Formation formation;

    @OneToOne
    @JoinColumn(name = "id_adp")
    public AssistantDePrevention assistantDePrevention;

    @Column(name = "a_participe")
    public boolean aParticipe;

    @Column(name = "commentaire_participation")
    public String commentaireParticipation;

    @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REFRESH })
    @Column(name = "formation_remplacement")
    public ParticipationFormation formationRemplacement;
}

我尝试进行如下查询:

public static List<ParticipationFormation> search(JsonNode node) {
    ExpressionList<ParticipationFormation> query = ParticipationFormation.find.where();
    if (node.has("aParticipe"))
        query.eq("aParticipe", node.get("aParticipe").asBoolean());
    if (node.has("formation"))
        query.eq("formation", Formation.extract(node.get("formation")));
    if (node.has("assistantDePrevention"))
        query.eq("assistantDePrevention", AssistantDePrevention.extract(node.get("assistantDePrevention")));
    return query.findList();
}

extract() 方法具有用于从 Json 节点检索或创建 Bean 的特殊逻辑。

就我而言,节点只有一个“assistantDePrevention”字段。

当到达 findList() 时,出现此异常(我缩短了输出):

PersistenceException: Query threw new SQLException: Unknown column 't0.formation_remplacement_id' in 'field list'

当我删除级联信息时,它就起作用了。

有人可以解决我的问题或解释吗?

最佳答案

formationRemplacement 映射中将 @Column 更改为 @JoinColumn

关于java - 当我对自引用实体进行查询时出现 SQLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29415716/

相关文章:

java - java中JFrame是重量级组件还是轻量级组件?

java - 从另一个 Activity 获取textView的文本

java - 为 armeabi 编译的文件是否有 armeabi-v7a 的一些问题

java - 如何将查询的结果集映射到表以外的不同实体

scala - 集成客户端验证

java - 如何将场注入(inject)与 Action 组合一起使用?

java - 访问类并创建对象

jpa - 迁移 EJB2.x BMP 实体 bean

java - 如何在 JPA 2.1 中映射来自 NameStoredProcedure 的非实体结果集?

java - Play Framework WS url 空间