| 항목 | 내용 |
|---|---|
| JDK 최소 버전 | Java 17 이상 |
| JPA 버전 | Hibernate 6 이상 |
| javax → jakarta | 모든 JPA 애너테이션이 javax.persistence → jakarta.persistence 로 변경됨 |
| 날짜/시간 타입 | LocalDateTime 권장, @Temporal 불필요 |
spring.jpa.hibernate.ddl-auto | none, validate, update, create, create-drop 중 선택 (생성 목적이면 create 사용 가능) |
Spring Boot 3.x 기준)package com.example.demo.domain;
import jakarta.persistence.*;
import java.time.LocalDateTime;
@Entity
@Table(name = "product")
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY) // MySQL auto_increment 대응
private Long id;
@Column(name = "product_name", nullable = false, length = 100)
private String name;
@Column(name = "price", nullable = false)
private int price;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
private Category category;
@Column(name = "created_at", updatable = false)
private LocalDateTime createdAt;
@Column(name = "updated_at")
private LocalDateTime updatedAt;
// 생성자, getter/setter, toString 등 생략 가능 (Lombok 사용 가능)
}
package com.example.demo.domain;
import jakarta.persistence.*;
import java.util.List;
@Entity
@Table(name = "category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "category_name", nullable = false, length = 50)
private String name;
// 읽기 전용 매핑 (양방향 필요 시)
@OneToMany(mappedBy = "category", fetch = FetchType.LAZY)
private List<Product> products;
}
spring:
datasource:
url: jdbc:mysql://localhost:3306/demo
username: root
password: password
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: none # 생성은 안 하고, 오직 매핑용으로만 쓸 때는 none 또는 validate
properties:
hibernate:
format_sql: true
show_sql: true
jakarta.persistence 패키지를 사용하세요 (Spring Boot 3.0 이상에서는 필수).LocalDateTime을 직접 사용하면 되므로 @Temporal은 필요 없습니다.@Entity, @Table, @Id, @Column, @ManyToOne, @JoinColumn 정도만 사용하시면 충분합니다.spring.jpa.hibernate.ddl-auto는 none 또는 validate로 설정하세요 (DB는 수동 관리한다는 의미).필요하시면 이 구조에 맞춰 기본적인 초기화 SQL (schema.sql)도 만들어 드릴 수 있습니다.
또는 DDL 자동 생성 로그 확인하는 법도 알려드릴게요. 필요한 거 있으면 편하게 말씀 주세요!