프로젝트 세팅
xxxxxxxxxx //도메인 클래스public class Account { private Long id; private String username; private String password; // @column을 안붙혀도 Entity어노테이션 때메 기본적으로 // 테이블에 매핑 생략 돼 있는거나 마찬가지}Entity : 이 객체가 DB랑 연동될 엔티티 라는 것을 알려줌
Getter,Setter : 롬복 어노테이션
Id : pk 값
GenerateValue : id 값을 따로 설정하지 않아도 알아서 증가해서 id값을 넣어준다
xxxxxxxxxxpublic class JpaRunner implements ApplicationRunner { // jpa어노테이션을 이용해서 엔티티 매니저라는 jpa의 핵심적인 빈을 주입받을수 있다 EntityManager entityManager; // 이것을 가지고 데이터를 영속화 할 수 있다. //영속화란 데이터베이스에 저장 public void run(ApplicationArguments args) throws Exception { Account account = new Account(); account.setUsername("suhyeok"); account.setPassword("1234"); entityManager.persist(account); //한 엔티티매니저와 관련된 모든 행동은 한 트랜잭션 내부에서 일어나야 한다. }}
결과 확인
![]()
'Spring Data JPA' 카테고리의 다른 글
| 06 JPA 프로그래밍 - 스프링 Data JPA 원리 (0) | 2020.06.19 |
|---|---|
| 05 JPA 프로그래밍 - Fetch , Query (0) | 2020.06.19 |
| 04 JPA 프로그래밍 - 엔티티 상태와 cascade (0) | 2020.06.19 |
| 03. JPA프로그래밍 -엔티티 매핑 (0) | 2020.06.16 |
| 01. 관계형 데이터베이스, ORM (0) | 2020.06.16 |
