我有一个根据此模式构建的实体:
@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/