diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/FoodCategory.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/FoodCategory.java" new file mode 100644 index 0000000..72e531e --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/FoodCategory.java" @@ -0,0 +1,21 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class FoodCategory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false,length = 15) + private String name; + + +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Member.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Member.java" new file mode 100644 index 0000000..b9db766 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Member.java" @@ -0,0 +1,67 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import lombok.*; +import umc.spring.domain.common.BaseEntity; +import umc.spring.domain.enums.Gender; +import umc.spring.domain.enums.MemberStatus; +import umc.spring.domain.enums.SocialType; +import umc.spring.domain.mapping.MemberAgree; +import umc.spring.domain.mapping.MemberMission; +import umc.spring.domain.mapping.MemberPrefer; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Member extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false,length = 20) + private String name; + + private Integer age; + + @Column(nullable = false,length = 40) + private String address; + + @Column(nullable = false,length = 40) + private String specAddress; + + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "VARCHAR(10)") + private Gender gender; + + @Enumerated(EnumType.STRING) + private SocialType socialType; + + @Enumerated(EnumType.STRING) + @Column(columnDefinition = "VARCHAR(15) DEFAULT 'ACTIVE'") + private MemberStatus memberStatus; + + private LocalDate inactiveDate; + + @Column(nullable = false, length = 50) + private String email; + + private Integer point; + + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + private List memberAgreeList = new ArrayList<>(); + + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + private List memberPreferList = new ArrayList<>(); + + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + private List reviewList = new ArrayList<>(); + + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + private List memberMissionList = new ArrayList<>(); + +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Mission.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Mission.java" new file mode 100644 index 0000000..10f9c32 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Mission.java" @@ -0,0 +1,33 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import umc.spring.domain.common.BaseEntity; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +import lombok.*; +import umc.spring.domain.mapping.MemberMission; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Mission extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private Integer reward; + + private LocalDateTime deadline; + + private String mission_spec; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id") + private Store store; + + @OneToMany(mappedBy = "mission", cascade = CascadeType.ALL) + private List memberMissionList = new ArrayList<>(); +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Region.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Region.java" new file mode 100644 index 0000000..fc679ef --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Region.java" @@ -0,0 +1,25 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import umc.spring.domain.common.BaseEntity; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Region extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false,length = 20) + private String name; + + @OneToMany(mappedBy = "region",cascade = CascadeType.ALL) + private List storeList=new ArrayList<>(); + +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Review.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Review.java" new file mode 100644 index 0000000..dfe8693 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Review.java" @@ -0,0 +1,29 @@ +package umc.spring.domain; + + +import jakarta.persistence.*; +import umc.spring.domain.common.BaseEntity; +import lombok.*; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Review extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String body; + + private Float score; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id") + private Store store; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/ReviewImage.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/ReviewImage.java" new file mode 100644 index 0000000..2b4abfe --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/ReviewImage.java" @@ -0,0 +1,21 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import lombok.*; +import umc.spring.domain.common.BaseEntity; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class ReviewImage extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String image_url; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "review_id") + private Review review; +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Store.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Store.java" new file mode 100644 index 0000000..618485a --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Store.java" @@ -0,0 +1,33 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import umc.spring.domain.common.BaseEntity; +import lombok.*; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Store extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false,length = 50) + private String name; + + @Column(nullable = false,length = 50) + private String address; + + private Float score; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "region_id") + private Region region; + + @OneToMany(mappedBy = "store",cascade = CascadeType.ALL) + private List reviewList=new ArrayList<>(); +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Terms.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Terms.java" new file mode 100644 index 0000000..633e54d --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/Terms.java" @@ -0,0 +1,29 @@ +package umc.spring.domain; + +import jakarta.persistence.*; +import umc.spring.domain.common.BaseEntity; +import lombok.*; +import umc.spring.domain.mapping.MemberAgree; + +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Terms extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false,length = 20) + private String title; + + private String body; + + private Boolean optional; + + @OneToMany(mappedBy = "terms", cascade = CascadeType.ALL) + private List memberAgreeList = new ArrayList<>(); +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/common/BaseEntity.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/common/BaseEntity.java" new file mode 100644 index 0000000..7abfac2 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/common/BaseEntity.java" @@ -0,0 +1,20 @@ +package umc.spring.domain.common; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; + +import java.time.LocalDateTime; + +@MappedSuperclass +@EntityListeners(AbstractMethodError.class) +@Getter +public abstract class BaseEntity { + @CreatedDate + private LocalDateTime createdAt; + + @LastModifiedDate + private LocalDateTime updatedAt; +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/Gender.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/Gender.java" new file mode 100644 index 0000000..5d1bd65 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/Gender.java" @@ -0,0 +1,5 @@ +package umc.spring.domain.enums; + +public enum Gender { + MALE,FEMALE +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/MemberStatus.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/MemberStatus.java" new file mode 100644 index 0000000..48d84ba --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/MemberStatus.java" @@ -0,0 +1,5 @@ +package umc.spring.domain.enums; + +public enum MemberStatus { + ACTIVE,INACTIVE +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/SocialType.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/SocialType.java" new file mode 100644 index 0000000..6206309 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/enums/SocialType.java" @@ -0,0 +1,5 @@ +package umc.spring.domain.enums; + +public enum SocialType { + KAKAO,GOOGLE,NAVER,APPLE +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberAgree.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberAgree.java" new file mode 100644 index 0000000..0842fe1 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberAgree.java" @@ -0,0 +1,25 @@ +package umc.spring.domain.mapping; + +import jakarta.persistence.*; +import umc.spring.domain.Member; +import umc.spring.domain.Terms; +import umc.spring.domain.common.BaseEntity; +import lombok.*; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class MemberAgree extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch =FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name="terms_id") + private Terms terms; +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberMission.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberMission.java" new file mode 100644 index 0000000..83e2875 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberMission.java" @@ -0,0 +1,28 @@ +package umc.spring.domain.mapping; + +import jakarta.persistence.*; +import lombok.*; +import umc.spring.domain.Member; +import umc.spring.domain.Mission; +import umc.spring.domain.common.BaseEntity; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class MemberMission extends BaseEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Enumerated(EnumType.STRING) + private MissionStatus status; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "mission_id") + private Mission mission; +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberPrefer.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberPrefer.java" new file mode 100644 index 0000000..01ca650 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MemberPrefer.java" @@ -0,0 +1,27 @@ +package umc.spring.domain.mapping; + +import jakarta.persistence.*; +import lombok.*; +import umc.spring.domain.FoodCategory; +import umc.spring.domain.Member; +import umc.spring.domain.common.BaseEntity; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class MemberPrefer extends BaseEntity { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch= FetchType.LAZY) //지연로딩 설정 + @JoinColumn(name = "member_id") + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private FoodCategory foodCategory; + +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MissionStatus.java" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MissionStatus.java" new file mode 100644 index 0000000..f090fb4 --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/java/umc/spring/domain/mapping/MissionStatus.java" @@ -0,0 +1,5 @@ +package umc.spring.domain.mapping; + +public enum MissionStatus { + CHALLENGING, COMPLETE +} diff --git "a/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/resources/application.yml" "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/resources/application.yml" new file mode 100644 index 0000000..d98554d --- /dev/null +++ "b/dldusgh318/\354\233\214\355\201\254\353\266\201/spring/spring/src/main/resources/application.yml" @@ -0,0 +1,24 @@ +spring: + datasource: + url: jdbc:h2:tcp://localhost/~/umcspring + username: sa + password: + driver-class-name: org.h2.Driver + + jpa: + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.H2Dialect +# show_sql: true +# use_sql_comments: true +# hbm2ddl: +# auto: create + default_batch_fetch_size: 1000 + +logging: + level: + org.hibernate.SQL: debug + org.hibernate.orm.jdbc.bind: trace \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/compiler.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/compiler.xml" new file mode 100644 index 0000000..0ce7f68 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/compiler.xml" @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/encodings.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/encodings.xml" new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/encodings.xml" @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/jarRepositories.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/jarRepositories.xml" new file mode 100644 index 0000000..712ab9d --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/jarRepositories.xml" @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/misc.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/misc.xml" new file mode 100644 index 0000000..a8fc129 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/misc.xml" @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/vcs.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/vcs.xml" new file mode 100644 index 0000000..def3818 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/vcs.xml" @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/workspace.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/workspace.xml" new file mode 100644 index 0000000..06eaaf2 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/.idea/workspace.xml" @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "last_opened_file_path": "C:/Users/polol/OneDrive/바탕 화면/UMC-6th-Spring-Study/dldusgh318/자바ORM/ex1-hello-jpa", + "project.structure.last.edited": "Project", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.0", + "settings.editor.selected.configurable": "reference.projectsettings.compiler.javacompiler" + } +} + + + + + + + + + + + + + + + + + + + + + + 1716357237799 + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/pom.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/pom.xml" new file mode 100644 index 0000000..c854ee9 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/pom.xml" @@ -0,0 +1,48 @@ + + + 4.0.0 + + jpa-basic + ex1-hello-jpa + 1.0.0 + + + 17 + 17 + UTF-8 + + + + + + org.hibernate + hibernate-core + 6.4.2.Final + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + + + com.h2database + h2 + 2.2.224 + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/JpaMain.java" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/JpaMain.java" new file mode 100644 index 0000000..4f68e91 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/JpaMain.java" @@ -0,0 +1,32 @@ +package hellojpa; + +import jakarta.persistence.*; + +import java.util.List; + +public class JpaMain { + + public static void main(String[] args) { + + EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");//설정파일을 읽어옴 + EntityManager em = emf.createEntityManager(); + + EntityTransaction tx = em.getTransaction(); + tx.begin(); + try{ + + Member member = new Member(); + member.setUsername("C"); + + em.persist(member); + + tx.commit(); //코드 결과 반영 ㅇㅇ + } catch(Exception e) { + tx.rollback(); + } finally { + em.close(); + } + + emf.close(); + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/Member.java" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/Member.java" new file mode 100644 index 0000000..219a752 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/Member.java" @@ -0,0 +1,41 @@ +package hellojpa; + +import jakarta.persistence.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; + +@Entity +@TableGenerator( + name = "MEMBER_SEQ_GENERATOR", + table = "MY_SEQUENCES", + pkColumnValue = "MEMBER_SEQ", allocationSize = 1) +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.TABLE,generator = "MEMBER_SEQ_GENERATOR") + private Long id; + + @Column(name = "name",nullable = false) + private String username; + + public Member(){ + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id=id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/RoleType.java" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/RoleType.java" new file mode 100644 index 0000000..cbe88f5 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/java/hellojpa/RoleType.java" @@ -0,0 +1,5 @@ +package hellojpa; + +public enum RoleType { + GUEST,USER,ADMIN; +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/META-INF/persistence.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/META-INF/persistence.xml" new file mode 100644 index 0000000..eda61b0 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/META-INF/persistence.xml" @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/logback.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/logback.xml" new file mode 100644 index 0000000..5b49cce --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/src/main/resources/logback.xml" @@ -0,0 +1,14 @@ + + + + + %d{HH:mm} %-5level %logger{36} - %msg%n + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/META-INF/persistence.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/META-INF/persistence.xml" new file mode 100644 index 0000000..eda61b0 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/META-INF/persistence.xml" @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/JpaMain.class" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/JpaMain.class" new file mode 100644 index 0000000..5b8f85a Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/JpaMain.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/Member.class" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/Member.class" new file mode 100644 index 0000000..6b063e6 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/Member.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/RoleType.class" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/RoleType.class" new file mode 100644 index 0000000..bd94566 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/hellojpa/RoleType.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/logback.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/logback.xml" new file mode 100644 index 0000000..5b49cce --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/ex1-hello-jpa/target/classes/logback.xml" @@ -0,0 +1,14 @@ + + + + + %d{HH:mm} %-5level %logger{36} - %msg%n + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/.gitignore" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/.gitignore" new file mode 100644 index 0000000..26d3352 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/.gitignore" @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/compiler.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/compiler.xml" new file mode 100644 index 0000000..ac6c43f --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/compiler.xml" @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/encodings.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/encodings.xml" new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/encodings.xml" @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/jarRepositories.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/jarRepositories.xml" new file mode 100644 index 0000000..712ab9d --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/jarRepositories.xml" @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/misc.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/misc.xml" new file mode 100644 index 0000000..d14a160 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/misc.xml" @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/vcs.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/vcs.xml" new file mode 100644 index 0000000..c2365ab --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/.idea/vcs.xml" @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/pom.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/pom.xml" new file mode 100644 index 0000000..c854ee9 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/pom.xml" @@ -0,0 +1,48 @@ + + + 4.0.0 + + jpa-basic + ex1-hello-jpa + 1.0.0 + + + 17 + 17 + UTF-8 + + + + + + org.hibernate + hibernate-core + 6.4.2.Final + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + + + com.h2database + h2 + 2.2.224 + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/JpaMain.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/JpaMain.java" new file mode 100644 index 0000000..be2b2a2 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/JpaMain.java" @@ -0,0 +1,30 @@ +package jpabook.jpashop; +import jakarta.persistence.*; +import jpabook.jpashop.domain.Member; +import jpabook.jpashop.domain.Order; + +import java.util.List; + +public class JpaMain { + + public static void main(String[] args) { + + EntityManagerFactory emf = Persistence.createEntityManagerFactory("hello");//설정파일을 읽어옴 + EntityManager em = emf.createEntityManager(); + + EntityTransaction tx = em.getTransaction(); + tx.begin(); + try{ + Order order = em.find(Order.class, 1L); + Member findMember = order.getMember(); + + tx.commit(); + } catch(Exception e) { + tx.rollback(); + } finally { + em.close(); + } + + emf.close(); + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Item.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Item.java" new file mode 100644 index 0000000..c010aa0 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Item.java" @@ -0,0 +1,50 @@ +package jpabook.jpashop.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +@Entity +public class Item { + + @Id @GeneratedValue + @Column(name="ITEM_ID") + private Long id; + + private String name; + private int price; + private int stockQuantity; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getStockQuantity() { + return stockQuantity; + } + + public void setStockQuantity(int stockQuantity) { + this.stockQuantity = stockQuantity; + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Member.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Member.java" new file mode 100644 index 0000000..ece56cf --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Member.java" @@ -0,0 +1,54 @@ +package jpabook.jpashop.domain; + +import jakarta.persistence.*; + +@Entity +public class Member { + @Id @GeneratedValue + @Column(name = "MEMBER_ID") + private Long id; + private String name; + private String city; + private String street; + private String zipcode; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getZipcode() { + return zipcode; + } + + public void setZipcode(String zipcode) { + this.zipcode = zipcode; + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Order.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Order.java" new file mode 100644 index 0000000..bd46991 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/Order.java" @@ -0,0 +1,58 @@ +package jpabook.jpashop.domain; + +import jakarta.persistence.*; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "ORDERS") +public class Order { + @Id @GeneratedValue + @Column(name = "ORDER_ID") + private Long id; + + @Column(name = "MEMBER_ID") + private Long memberId; + + private Member member; + + public Member getMember() { + return member; + } + + private LocalDateTime orderDate; + @Enumerated(EnumType.STRING) + private OrderStatus status; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getMemberId() { + return memberId; + } + + public void setMemberId(Long memberId) { + this.memberId = memberId; + } + + public LocalDateTime getOrderDate() { + return orderDate; + } + + public void setOrderDate(LocalDateTime orderDate) { + this.orderDate = orderDate; + } + + public OrderStatus getStatus() { + return status; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderItem.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderItem.java" new file mode 100644 index 0000000..4b7139d --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderItem.java" @@ -0,0 +1,63 @@ +package jpabook.jpashop.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +@Entity +public class OrderItem { + + @Id @GeneratedValue + @Column(name = "ORDER_ITEM_ID") + private Long id; + + @Column(name = "ORDER_ID") + private Long orderId; + + @Column(name = "ITEM_ID") + private Long itemId; + + private int orderPrice; + private int count; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getOrderId() { + return orderId; + } + + public void setOrderId(Long orderId) { + this.orderId = orderId; + } + + public Long getItemId() { + return itemId; + } + + public void setItemId(Long itemId) { + this.itemId = itemId; + } + + public int getOrderPrice() { + return orderPrice; + } + + public void setOrderPrice(int orderPrice) { + this.orderPrice = orderPrice; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderStatus.java" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderStatus.java" new file mode 100644 index 0000000..585e384 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/java/jpabook/jpashop/domain/OrderStatus.java" @@ -0,0 +1,5 @@ +package jpabook.jpashop.domain; + +public enum OrderStatus { + ORDER,CANCEL +} diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/META-INF/persistence.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/META-INF/persistence.xml" new file mode 100644 index 0000000..99000b9 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/META-INF/persistence.xml" @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/logback.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/logback.xml" new file mode 100644 index 0000000..5b49cce --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/src/main/resources/logback.xml" @@ -0,0 +1,14 @@ + + + + + %d{HH:mm} %-5level %logger{36} - %msg%n + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/META-INF/persistence.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/META-INF/persistence.xml" new file mode 100644 index 0000000..99000b9 --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/META-INF/persistence.xml" @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/JpaMain.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/JpaMain.class" new file mode 100644 index 0000000..aa87056 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/JpaMain.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Item.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Item.class" new file mode 100644 index 0000000..6a2cdd9 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Item.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Member.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Member.class" new file mode 100644 index 0000000..e0ebafa Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Member.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Order.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Order.class" new file mode 100644 index 0000000..5fdbd97 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/Order.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderItem.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderItem.class" new file mode 100644 index 0000000..fb911db Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderItem.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderStatus.class" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderStatus.class" new file mode 100644 index 0000000..9e9b121 Binary files /dev/null and "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/jpabook/jpashop/domain/OrderStatus.class" differ diff --git "a/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/logback.xml" "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/logback.xml" new file mode 100644 index 0000000..5b49cce --- /dev/null +++ "b/dldusgh318/\354\236\220\353\260\224ORM/jpashop/target/classes/logback.xml" @@ -0,0 +1,14 @@ + + + + + %d{HH:mm} %-5level %logger{36} - %msg%n + + + + + + + + +