السلام عليكم
تواجهنى مشكله حين استخدم
spring mvc @responsebody
ويحدث هذا الاكسبشن
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.revo.entity.Post["person"]->org.revo.entity.Person_$$_jvst35a_6["post"]->org.hibernate.collection.PersistentBag[0]->
recursion ومعناه انه يحدث
لانه عندم يقوم ببناء json
لpost
فنه يجد بداخله person
وperson يجد بداخله
post
ويحدث recurision
كيف اتغلب على هذه المشكله
الاكواد
@RequestMapping(value = "/more/{start}", method = RequestMethod.GET)
@ResponseBody
public List<Post> more(@PathVariable("start") int start) {
int count = (int) postSer.ByProjection(Projections.rowCount());
if (start < count) {
List<Post> posts = postSer.posts(start, 5);
return posts;
} else {
return null;
}
}
@Override
public List<Post> posts(int first, int max) {
Criteria criteria = getSession().createCriteria(typeClass);
criteria.setFirstResult(first);
criteria.setMaxResults(max);
criteria.addOrder(Order.desc("postdate"));
return criteria.list();
}
@Entity
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private int id;
private String username;
private String email;
private String password;
private int type;
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Post> post;
}
@Entity
public class Post implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private int id;
private String txt;
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date postdate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private Person person;
}