使用JPA和ManyToMany进行Spring启动:JsonIdentifyInfo无法正常工作

我有两个导致问题的类: TeacherSchoolClassclass已经是Java关键字)。 两者都有很long id.

老师可以有很多class级,class级可以有很多老师。

如果我要求老师,我会(只有重要的变量)

 { "classes": [ { "teachers": [ { "classes": [ 1 ], } ], } ] } 

但如果我要求上课(完成)

 { "timestamp": 1445530016078, "status": 500, "error": "Internal Server Error", "exception": "org.springframework.http.converter.HttpMessageNotWritableException", "message": "Could not write content: java.lang.Integer cannot be cast to java.lang.Long (through reference chain: at.scool.model.db.SchoolClass[\"teachers\"]->java.util.HashSet[0]->at.scool.model.db.Teacher[\"classes\"]->java.util.HashSet[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.lang.Integer cannot be cast to java.lang.Long (through reference chain: at.scool.model.db.SchoolClass[\"teachers\"]->java.util.HashSet[0]->at.scool.model.db.Teacher[\"classes\"]->java.util.HashSet[0])", "path": "/api/class/1" } 

老师

 @ManyToMany @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") private Set classes = new HashSet(); 

SchoolClass

 @ManyToMany @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") private Set teachers = new HashSet(); 

如何解决此错误?

更新

我现在注意到, property值’id’不在SchoolClass中。 (在教师设置上使用JsonIgnore开始输出)

 { "@id": 1, "id": 1,