TIL

220704 TIL 실전프로젝트 트러블슈팅

Vince_rf 2022. 7. 4. 03:38

# query did not return a unique result: 2;

이런 에러가 발생했는데

List<객체> findAllby 가 아닌,

이건 객체를 findAllby~~ 로 찾아서 발생한 오류같다.

즉, List<객체> findAllby~~ 로 하면 해결될 것.


# @JsonManagedReference, @JsonBackReference

어노테이션들로 문제가 발생했다. 

Meeting 엔티티의 OneToMany에 @JsonManagedReference가 있고,

Issue 엔티티의 ManyToOne에 @JsonBackReference가 없으면

Issue가 여러개일 때,

*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844

java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

ERROR 5000 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting.Meeting["meetingIssue"]->org.hibernate.collection.internal.PersistentBag[0]->com.team.unanimous.model.meeting.Issue["meeting"]->com.team.unanimous.model.meeting

이런 오류들이 주우우우욱 나타난다.

OneToMany에 @JsonManagedReference가 없고, ManyToOne에 @JsonBackReference가 있으면

미팅이 여러개일 때, 저런 에러가 나타난다.

즉, OneToMany와 ManyToOne 로 묶여있는 연관관계에서는 해당 어노테이션들을 잘 넣어주자.. 

# update메서드가 안 먹힐때,

sout 로 찍어도 바뀌는데 DB에 적용이 안 될 때는

update 아래에
마지막으로 repository.save 를 해주면 잘 적용된다.