-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Tave12st-Backend-Study/limjunhyoung
[Week1] [Chapter1~3] Limjunhyoung
- Loading branch information
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>jpabasic</groupId> | ||
<artifactId>reviewjpa</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- JPA 하이버네이트 --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-entitymanager</artifactId> | ||
<version>5.3.10.Final</version> | ||
</dependency> | ||
<!-- H2 데이터베이스 --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>1.4.199</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.22</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- java 11은 아래의 의존성 필수 --> | ||
|
||
<!-- JAXB Dependency --> | ||
<dependency> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package reviewjpa; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.EntityTransaction; | ||
import javax.persistence.Persistence; | ||
import java.util.List; | ||
|
||
public class JpaMain { | ||
public static void main(String[] args) { | ||
|
||
EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("hello"); | ||
EntityManager em = emFactory.createEntityManager(); | ||
// code 시작 | ||
|
||
EntityTransaction tx = em.getTransaction(); | ||
tx.begin(); // transaction 시작 | ||
|
||
try { | ||
|
||
Member member = em.find(Member.class, 1L); | ||
member.setName("ㅁㅁㅁㅁ"); | ||
|
||
// JPA에서 관리 안함 | ||
em.detach(member); | ||
|
||
System.out.println("--------------------"); | ||
tx.commit(); // 성공하면 커밋 | ||
|
||
} catch (Exception e) { | ||
tx.rollback(); // 실패하면 롤백 | ||
} finally { | ||
em.close(); | ||
} | ||
|
||
emFactory.close(); | ||
// code 끝 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package reviewjpa; | ||
|
||
import lombok.*; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Entity | ||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Member { | ||
|
||
@Id | ||
private Long id; | ||
|
||
private String name; | ||
} |
20 changes: 20 additions & 0 deletions
20
임준형/basic/reviewjpa/src/main/resources/META-INF/persistence.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?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/persistence_2_2.xsd"> | ||
<persistence-unit name="hello"> | ||
<properties> | ||
<!-- 필수 속성 --> | ||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/> | ||
<property name="javax.persistence.jdbc.user" value="sa"/> | ||
<property name="javax.persistence.jdbc.password" value=""/> | ||
<property name="javax.persistence.jdbc.url" value="jdbc:h2:tcp://localhost/~/test"/> | ||
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> | ||
<!-- 옵션 --> | ||
<property name="hibernate.show_sql" value="true"/> | ||
<property name="hibernate.format_sql" value="true"/> | ||
<property name="hibernate.use_sql_comments" value="true"/> | ||
<!-- <property name="hibernate.hbm2ddl.auto" value="create" />--> | ||
</properties> | ||
</persistence-unit> | ||
</persistence> |