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

SQLException when I make a query on a self-referenced entity

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

@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