JPA 시작하기
환경 설정 & 프로젝트 생성
1. H2 Database
[H2] 버전 확인 명령어
😎 문제 발생 H2 버전 포맷 에러가 발생해서 버전 확인을 해보려고 구글링을 통해 SQL문을 찾았다. SELECT H2VERSION() FROM DUAL; 😃 확인 방법 H2를 실행시키고, Console 창에 입력 한 후 결과값에서 확인
96-brain.tistory.com
2. Maven → 프로젝트 생성
[IntelliJ] 인텔리제이 maven 프로젝트 생성하기
1. File > New > Project > New Project Name : 프로젝트 이름 Location : 프로젝트 생성 위치 Create Git repository : Git 저장소를 생성합니다. Language : 여기서는 Java를 선택하였습니다. Build system : Maven을 선택합니다.
hianna.tistory.com
Your relational data. Objectively. - Hibernate ORM
Idiomatic persistence for Java and relational databases.
hibernate.org
Spring Boot Reference Documentation
This section goes into more detail about how you should use Spring Boot. It covers topics such as build systems, auto-configuration, and how to run your applications. We also cover some Spring Boot best practices. Although there is nothing particularly spe
docs.spring.io
JPA, Hibernate, H2 database → Spring Boot를 지원하는 버전으로 설치하는게 가장 좋다
3. pom.xml
Maven 프로젝트에 라이브러리를 추가하기 위해 사용되는 설정 xml 파일
4. persistence.xml
- JPA 설정에 사용되는 xml 파일
src/main/resources/META-INF/persistence.xml
에 위치한다show_sql
,format_sql
,use_sql_comments
등은 디버깅을 할 때 JPA로 짠 코드를 SQL로 변환하여 보여줄 것인지에 대한 옵션이다.
애플리케이션 개발
JPA를 활용한 Spring Boot의 기본적인 형태는 아래와 같다.
Member
@Entity
: JPA가 관리할 객체@Id
: DB PK와 매핑