Hibernate 无法用@Formula填充多对多关系中的列

Hibernate 无法用@Formula填充多对多关系中的列,hibernate,many-to-many,Hibernate,Many To Many,我有两个班,评估和回复,与多对多的关系联系在一起。 评估代码如下所示: @Entity public class Evaluation implements Serializable { private Long id; @ManyToMany public List<Reponse> getListOfReponses() { return listOfReponses; } @Formula("(SELECT COUNT(*) FROM Evaluation_Rep

我有两个班,评估和回复,与多对多的关系联系在一起。 评估代码如下所示:

@Entity
public class Evaluation implements Serializable {

private Long id;

@ManyToMany
public List<Reponse> getListOfReponses() {
    return listOfReponses;
}

@Formula("(SELECT COUNT(*) FROM Evaluation_Reponse er, Reponse r, WHERE er.Evaluation_id = id AND r.id = er.listOfReponses_id AND r.correct = 1)")
public Integer getNbCorrectAnswers() {
return nbCorrectAnswers;
}

Correct是Reponse的一个属性,是一个布尔值

如您所见,我编写了一个hibernate公式来填充nbCorrectAnswers列。但是,当我保存评估时,除了nbCorrectAnswers列保持为空之外,其他一切都正常工作

那么,你能告诉我公式中有什么错误,或者如何正确填写我的整个表格吗?
谢谢

公式始终是只读的。hibernate假定您有其他一些代码/实体插入这些值。AFAIK公式也仅在从数据库加载时计算