-
Notifications
You must be signed in to change notification settings - Fork 0
[fedragon] Chapter 4. JPA 기초 및 프로젝트 구조 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example.umc9th; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
|
||
| @SpringBootApplication | ||
| @EnableJpaAuditing // 👈 이 어노테이션을 꼭 추가해주세요! | ||
| public class Umc9thApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(Umc9thApplication.class, args); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.umc9th.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 org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| @Getter | ||
| public abstract class BaseEntity { | ||
| @CreatedDate | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @LastModifiedDate | ||
| private LocalDateTime updatedAt; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.umc9th.domain.food.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.food.enums.FoodName; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Food extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(columnDefinition = "VARCHAR(20)") | ||
| private FoodName name; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.example.umc9th.domain.food.enums; | ||
|
|
||
| public enum FoodName { | ||
| KOREAN_FOOD, CHINESE_FOOD, JAPANESE_FOOD, WESTERN_FOOD, BUNSIK, CAFE_DESSERT | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1:N 연관관계 매핑이 안되어 있어요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.example.umc9th.domain.location.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Location extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, length = 50) | ||
| private String name; | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1:N 연관관계 매핑이 안되어 있어요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.umc9th.domain.mission.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.store.entity.Store; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Mission extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private LocalDate deadline; | ||
|
|
||
| @Column(length = 200) | ||
| private String conditional; | ||
|
|
||
| private Integer point; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "store_id") | ||
| private Store store; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.example.umc9th.domain.review.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.store.entity.Store; | ||
| import com.example.umc9th.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Review extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(columnDefinition = "TEXT") | ||
| private String content; | ||
|
|
||
| private Float star; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id") | ||
| private User user; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "store_id") | ||
| private Store store; | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1:N 연관관계 매핑이 안되어 있어요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.umc9th.domain.store.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.location.entity.Location; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @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(name = "zip_code", length = 10) | ||
| private String zipCode; | ||
|
|
||
| @Column(name = "detail_address", length = 100) | ||
| private String detailAddress; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "location_id") | ||
| private Location location; | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1:N 연관관계 매핑이 안되어 있어요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.example.umc9th.domain.term.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Term extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, length = 100) | ||
| private String name; | ||
| } |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1:N 연관관계 매핑이 안되어 있어요 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.example.umc9th.domain.user.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.user.enums.Gender; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import java.time.LocalDate; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class User extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, length = 20) | ||
| private String name; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(columnDefinition = "VARCHAR(10)") | ||
| private Gender gender; | ||
|
|
||
| @Column(length = 40) | ||
| private String address; | ||
|
|
||
| private LocalDate birth; | ||
|
|
||
| @Column(length = 50) | ||
| private String email; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이메일 주소의 length 는 255로 하는것이 좋을거같아요. 50자를 넘는 이메일도 존재할 수 있어요.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러네요 감사합니다 |
||
|
|
||
| @Column(name = "phone_number", length = 20) | ||
| private String phoneNumber; | ||
|
|
||
| private LocalDate deletedAt; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.example.umc9th.domain.user.enums; | ||
|
|
||
| public enum Gender { | ||
| MALE, FEMALE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.example.umc9th.domain.user_food.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.food.entity.Food; | ||
| import com.example.umc9th.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class UserFood extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id") | ||
| private User user; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "food_id") | ||
| private Food food; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.example.umc9th.domain.user_mission.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.mission.entity.Mission; | ||
| import com.example.umc9th.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class UserMission extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private Boolean complete; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id") | ||
| private User user; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "mission_id") | ||
| private Mission mission; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.example.umc9th.domain.user_term.entity; | ||
|
|
||
| import com.example.umc9th.domain.common.BaseEntity; | ||
| import com.example.umc9th.domain.term.entity.Term; | ||
| import com.example.umc9th.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class UserTerm extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "user_id") | ||
| private User user; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "term_id") | ||
| private Term term; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| spring: | ||
| # === ?????? ?? ?? === | ||
| datasource: | ||
| driver-class-name: com.mysql.cj.jdbc.Driver | ||
| # 'umc9th2' ??????? ?????. MySQL Workbench?? ?? ??????! | ||
| url: jdbc:mysql://localhost:3306/umc9th2?serverTimezone=Asia/Seoul&useSSL=false | ||
| username: root | ||
| password: ssms101504@ # ? ??? ?? ????? ?????! | ||
|
|
||
| # === JPA(?????? ??? ??) ?? === | ||
| jpa: | ||
| hibernate: | ||
| # ? ?? ??? ?? ??? ?? DB ???? ???? ??????. | ||
| ddl-auto: create | ||
| properties: | ||
| hibernate: | ||
| # ???? SQL ??? ??? ? ? ?? ??? ?????. | ||
| show_sql: true | ||
| format_sql: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example.umc9th; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
|
|
||
| @SpringBootTest | ||
| class Umc9thApplicationTests { | ||
|
|
||
| @Test | ||
| void contextLoads() { | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1:N 연관관계 매핑이 안되어 있어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@onetomany