728x90
JPA
- dependencies
- h2
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>2.1.214</version> <scope>test</scope> </dependency>
- hibernate
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>5.6.15.Final</version> </dependency>
- persistence.xml
```xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/">
<!-- EntityManagerFactory 생성 시 unit name과 일치해야 합니다 -->
<persistence-unit name="com.hiio">
<properties>
<!-- 필수 속성 -->
<!-- DB Driver -->
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<!-- DB user info -->
<property name="javax.persistence.jdbc.user" value="hiio"/>
<property name="javax.persistence.jdbc.password" value="hiio"/>
<!-- DB url -->
<property name="javax.persistence.jdbc.url" value="jdbc:h2:file:F:/data/h2/prac"/>
<!-- Dialect -->
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<!-- 옵션 -->
<!-- SQL show -->
<property name="hibernate.show_sql" value="true"/>
<!-- SQL 정렬 -->
<property name="hibernate.format_sql" value="true"/>
<!-- SQL에 관한 주석 처리 -->
<property name="hibernate.use_sql_comments" value="true"/>
<!-- application 실행 시 ddl 전략 -->
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
- lombok
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.26</version> <scope>provided</scope> </dependency>
- Annotation
- @Entity : 테이블 매핑한다고 알려준다
- @Table : 매핑할 테이블 정보 / 생략시 class 이름을 매핑
- @Id : 식별자 필드 / 기본키
- @Column : 컬럼 매핑
- application jpa 순선
- EntityManagerFactory 생성
- EntityyManager 생성
- EntityTransaction 생성
- 트랜잭션 begin()
- 로직
- 트랜잭션 commit()
- 에러 : rollback()
- EntityManager close()
- EntityManagerFactory close()
- 로직
- 등록 EntityManager save + Entity Object
- find
- setter 수정
- em.remove(Entity Object) 삭제
- createQuery + getResultList
- Entity Object .class
- 문제는 검색쿼리
- JPQL : Entity Object 를 대상으로 한다.
- Error
- No default constructor for entity: 기본 생성자 추가해주기
이클립스
- 메모리 늘리기
- 'Preferences - General - Show heap status'를 체크
- eclipse.ini 파일을 수정
- Xms256m -> Xms1024m
728x90