강의

멘토링

로드맵

Inflearn Community Q&A

easyvvon's profile image
easyvvon

asked

Java ORM Standard JPA Programming - Basics

Default Key Mapping

MySQL의 테이블 자동 생성 시에 대해서

Resolved

Written on

·

190

0

본 강의 내용대로,

Member 클래스

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MEMBER_ID")
private Long id;

persistence.xml

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>

로 설정하면 jpa 실행하면서 생성되는 테이블 컬럼에 'auto_increment'가 설정된 것을 확인했습니다.

그런데 Member 클래스의 @GeneratedValue 속성만 기본 값(GenerationType.AUTO)으로 설정하면 auto_increment가 설정되지 않고, 마치 GenerationType.TABLE으로 설정한 것처럼 시퀀스용(=키 생성 전용) 테이블이 별도로 생성되는 것을 확인했습니다.

제가 궁금한 것은, @GeneratedValue 전략을 설정할 때, persistence.xml의 DB 방언 설정에 따라 같이 병행해야하나요?

JPAjava

Quiz

A class using the `@Entity` annotation for JPA mapping must basically meet these important conditions: 1. It must have a no-argument constructor (default constructor). 2. It must have a field representing the primary key, usually marked with the `@Id` annotation. 3. The class itself cannot be `final`. 4. It cannot be an `enum` or an `interface`.

All fields must be public

must be a final class

Must have a public or protected default constructor

must include at least one static method

Answer 1

2

yh님의 프로필 이미지
yh
Instructor

안녕하세요. 덩더러러쿨님

AUTO는 데이터베이스 방언에 따라서 각각 다르게 전략이 설정됩니다.

그래서 딱 정리해드리면, 실무에서는 AUTO를 사용하지 말고, 전략을 지정하는게 좋습니다.

감사합니다.

easyvvon's profile image
easyvvon

asked

Ask a question