simDev1234
심플하고 차분하게
simDev1234
전체 방문자
오늘
어제
  • 분류 전체보기
    • Computer Science
      • Basic Math
      • Data Structure
      • Algorithm
      • Database
      • OS
    • Language
      • Java
      • Kotlin
      • SQL
    • Framework
      • Spring
      • Orm&Mapper
      • 프로젝트로 스프링 이해하기
      • 스프링 라이브러리
    • Infra
      • Cloud
      • Docker
      • Redis
      • AWS, Azure
      • Device
    • Etc
      • CleanCoding
    • Git,Github

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • JVM메모리구조
  • scanner #next() #nextLine()
  • 참조타입
  • 404
  • null
  • 자바
  • 자바프로그래밍
  • 컨트롤러
  • 스프링
  • 자바프로그램
  • controllerTest
  • 참조변수
  • 자바메모리구조

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
simDev1234

심플하고 차분하게

Framework/Orm&Mapper

[JPA] repository.save()의 반환값이 안 들어올 때

2022. 10. 19. 15:00

|  상황

- repository.save()를 하면 Entity타입의 객체가 반환되어야 하는데 아래와 같이 null이 반환됐다.

/*Q14*/
// 트러블 슈팅 : 어? 뭐지? 데이터가 저장은 됐는데, Response값이 안온다.
// -- 원인 ) Entity 인스턴스 비교(equals)를 위해 equals, hashcode 필요
@PostMapping("/api/notice4")
public Notice addNotice4(@RequestBody NoticeRegister noticeRegister){
    return noticeRepository.save(
        Notice.builder()
                .title(noticeRegister.getTitle())
                .contents(noticeRegister.getContents())
                .build()
    );
}

>> Response

{}

 

|  해결방법

- Entity 객체에 @EqualsAndHashCode가 추가되면 된다.

- 나는 그냥 @Data를 넣어주었다.

 

[참고]

https://stackoverflow.com/questions/68429396/jparepository-save-methods-returns-null

 

'Framework > Orm&Mapper' 카테고리의 다른 글

[Transaction] Transaction에 대한 이해 (& 스프링의 @Transactionl)  (1) 2022.10.25
[JPA] 인텔리J에서 JPA Entity 기반 ERD 그리기  (0) 2022.10.19
[JPA] JPA 전반에 대해 간략히 이해하기  (0) 2022.10.06
[JPA] JPA 프로젝트를 생성, 엔터티 단위 CRUD (JPQL이란?)  (0) 2022.09.29
JPA란 무엇인가?  (0) 2022.09.27
    'Framework/Orm&Mapper' 카테고리의 다른 글
    • [Transaction] Transaction에 대한 이해 (& 스프링의 @Transactionl)
    • [JPA] 인텔리J에서 JPA Entity 기반 ERD 그리기
    • [JPA] JPA 전반에 대해 간략히 이해하기
    • [JPA] JPA 프로젝트를 생성, 엔터티 단위 CRUD (JPQL이란?)
    simDev1234
    simDev1234
    TIL용 블로그. * 저작권 이슈가 있는 부분이 있다면 댓글 부탁드립니다.

    티스토리툴바