inflearn logo
Course

Course

Instructor

gabozanet1044's Posts

gabozanet1044 gabozanet1044

@gabozanet1044

Reviews Written
4
Average Rating
5.0

Posts 12

Q&A

엔티티에 저장이 안되는 문제에 대한 문의

Optional car = carRepository .findById(s.getId()) ; 아.. 저건 필요없는건데, 저거 없이 했을때 안돼서 이렇게 저렇게 시도해보는 중에 들어간 부분입니다. 원래소스는 아래와 같습니다. campName으로 조회한 Camp도 잘 가져옵니다. @Service @Transactional @RequiredArgsConstructor public class CarService { private final CarRepository carRepository ; private final CampRepository campRepository ; @PostConstruct public void initCarData () throws IOException { if ( carRepository .count() > 0 ) { carRepository .findAll().stream().forEach(s -> { String campName = s.getCampEngName(); Camp camp = campRepository .findByEngName( campName ); if ( camp != null ) { addNote(s, camp ); } }); } } public void addNote ( Car car, Camp camp) { System . out .println( ">>>car = " + "" + car.getCarNumber() + ", camp = " + camp + ", campId = " + camp.getId()); car.setNote(camp.getKorName()); } } ------------------------------- 로그찍어보면 아래와같이 car 갯수만큼 잘 찍힙니다. >>>car = 81조4766, camp = 광주2(GWJ2)/광주(Gwangju), campId = 45 >>>car = 83보8744, camp = 인천5(ICH5)/인천(Incheon), campId = 5 --------------------------------- 근데, 컨트롤러에서 addNote 호출하면 정상적으로 저장이 됩니다.

Likes
0
Comments
7
Viewcount
682

Q&A

엔티티에 저장이 안되는 문제에 대한 문의

답변 감사합니다. 해당 코드는 서비스 부분에 위치하고 있습니다. 서비스 전체코드는 아래와 같습니다. 클래스 상단에 @transaction 도 기재했고요. 이렇게 해도 안돼서 문의 드렸습니다. @Service @Transactional @RequiredArgsConstructor public class CarService { private final CarRepository carRepository ; private final CampRepository campRepository ; @PostConstruct public void initCarData () { if ( carRepository .count() > 0 ) { carRepository .findAll().stream().forEach(s -> { String campName = s.getCampEngName() ; Optional car = carRepository .findById(s.getId()) ; Camp camp = campRepository .findByEngName(campName) ; if (camp != null ) { car.ifPresent(m -> addNote(m , camp )) ; } }) ; } } }

Likes
0
Comments
7
Viewcount
682

Q&A

deleteAllByMemberId 결과확인 문의(삭제가 안됨)

답변 감사합니다.~ 일반적으로 cascade 사용해서 알려주신 방식으로 처리하는것이 각각 제어하는것보다 좋은 방법인거죠? 아무래도 쿼리위주로 개발하던 방식과는 달라서 생소하긴 하네요. 위 수정된 부분 적용해서 수행해봤는데요, 제가 뭘 잘못한게 있는지 잘 안돼서 메일로 제가 수정한 파일 3개 첨부해서 드렸습니다. 함 확인 부탁드립니다. 즐거운 하루 보내세요~

Likes
0
Comments
6
Viewcount
432

Q&A

failed to lazily initialize a collection of role 오류 관련 문의

안녕하세요. 답변 감사합니다. 트랜잭션 말씀하셔서 소스 다시 봤더니 createSocialAccount 메쏘드에는 @Transaction 어노테이션 적용했는데 저걸 호출하는 메쏘드에는 안했네요. 이부분 추가했더니 정상 처리됩니다. @Transactional // public void setOauth2Member (MemberDto account) throws Exception { memberSocialProfile = memberSocialProfilesRepository .findByIdentifier(account.getIdentifier()) ; if ( memberSocialProfile == null ) { createSocialAccount(account) ; } } 그런데 이해가 안가는게, 위 호출부분에 @Transaction 없었을때, 질문과 같이 한번 생성은 되고 이후에 오류가 났는데 안되려면 초기 생성도 안되어야 하는거 아닌가요?

Likes
4
Comments
3
Viewcount
20786