当前位置: 动力学知识库 > 问答 > 编程问答 >

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

问题描述:

I have an Entity builded according this pattern :

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

}

I try to make a query like this :

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();

}

The extract() methods have a special logic for retrieving or creating beans from a Json Node.

In my case, node have only a "assistantDePrevention" field.

When findList() is reached, I have this Exception (I shortened the output) :

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

When I remove the cascading informations, it works.

Someone have a solution to my problem, or an explanation ?

网友答案:

Change @Column to @JoinColumn in formationRemplacement mapping.

分享给朋友:
您可能感兴趣的文章:
随机阅读: