danuri
오늘의 기록
danuri
전체 방문자
오늘
어제
  • 오늘의 기록 (307)
    • java (150)
      • java (33)
      • spring (63)
      • jpa (36)
      • querydsl (7)
      • intelliJ (9)
    • kotlin (8)
    • python (24)
      • python (10)
      • data analysis (13)
      • crawling (1)
    • ddd (2)
    • chatgpt (2)
    • algorithm (33)
      • theory (9)
      • problems (23)
    • http (8)
    • git (8)
    • database (5)
    • aws (12)
    • devops (10)
      • docker (6)
      • cicd (4)
    • book (44)
      • clean code (9)
      • 도메인 주도 개발 시작하기 (10)
      • 자바 최적화 (11)
      • 마이크로서비스 패턴 (0)
      • 스프링으로 시작하는 리액티브 프로그래밍 (14)
    • tistory (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

인기 글

태그

  • Bitmask
  • DDD
  • POSTGIS
  • 등가속도 운동
  • nuribank
  • Java
  • docker
  • PostgreSQL
  • JPA
  • ChatGPT
  • 트랜잭션
  • Security
  • Database
  • Jackson
  • gitlab
  • S3
  • connection
  • 자바 최적화
  • SWAGGER
  • Thymeleaf
  • 도메인 주도 설계
  • 마이크로서비스패턴
  • mockito
  • Saving Plans
  • Spring
  • CICD
  • reactive
  • AWS
  • RDS
  • Kotlin

최근 댓글

최근 글

hELLO · Designed By 정상우.
danuri

오늘의 기록

kotlin

[Kotlin] JPA 플러그인 정리

2024. 7. 19. 22:57

기본 생성자

@Entity 클래스는 기본 생성자를 가져야 한다.

why? JPA의 구현체인 hibernate는 기본생성자(protected 이상) + Reflection을 이용해 엔티티를 생성한다.

 

보통 kotlin 클래스는 다음과 같이 정의 하는데,

@Entity
class Customer private constructor(
    @EmbeddedId
    val id: CustomerId,
    var password: CustomerPassword,
    var name: String,
)

이러면 기본 생성자가 안생기니, 별도로 기본 생성자를 정의해줘야 하나 싶다.

-> kotlin-jpa 플러그인을 추가하면 @Entity, @MappedSuperClass, @Embeddable 클래스에 기본 생성자를 생성해준다.

 

ex) build.gradle.kts

plugins {
	...
	kotlin("plugin.jpa") version "1.9.20"
}

컴파일러 플러그인이어서, 컴파일 되기 전 직접적으로 호출할 수 없고, reflection을 통해서만 호출할 수 있기 때문에,

평소 코드를 작성할 때는 기본생성자가 없는 것처럼 생각할 수 있다.

 

참고자료

https://docs.jboss.org/hibernate/orm/6.1/userguide/html_single/Hibernate_User_Guide.html#entity

https://spring.io/guides/tutorials/spring-boot-kotlin

 

 

저작자표시 비영리 동일조건 (새창열림)

'kotlin' 카테고리의 다른 글

[Kotlin] @JvmOverloads - 생성자/함수 손쉽게 오버로딩  (0) 2025.02.23
[Kotlin] Private primary constructor is exposed via the generated 'copy()' method of a 'data' class.  (0) 2024.07.20
[Kotlin] 추가적으로 알아두어야 할 코틀린 특성  (0) 2023.06.20
[Kotlin] 코틀린에서의 FP  (0) 2023.06.04
[Kotlin] 코틀린에서의 OOP  (0) 2023.05.07
    'kotlin' 카테고리의 다른 글
    • [Kotlin] @JvmOverloads - 생성자/함수 손쉽게 오버로딩
    • [Kotlin] Private primary constructor is exposed via the generated 'copy()' method of a 'data' class.
    • [Kotlin] 추가적으로 알아두어야 할 코틀린 특성
    • [Kotlin] 코틀린에서의 FP
    danuri
    danuri
    IT 관련 정보(컴퓨터 지식, 개발)를 꾸준히 기록하는 블로그입니다.

    티스토리툴바