-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/8 create entity #9
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 |
|---|---|---|
|
|
@@ -37,3 +37,4 @@ out/ | |
| .vscode/ | ||
|
|
||
| .env | ||
| *.pem | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package ita.growin.domain.event.entity; | ||
|
|
||
| import ita.growin.domain.task.entity.Task; | ||
| import ita.growin.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class Event { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "event_id") | ||
| private Long id; | ||
|
|
||
| @OneToMany(mappedBy = "event", fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
| private List<Task> tasks; | ||
|
|
||
| @JoinColumn(name = "user_id") | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| private User user; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||
| package ita.growin.domain.task.entity; | ||||||||||||||
|
|
||||||||||||||
| import ita.growin.domain.event.entity.Event; | ||||||||||||||
| import jakarta.persistence.*; | ||||||||||||||
| import lombok.AccessLevel; | ||||||||||||||
| import lombok.AllArgsConstructor; | ||||||||||||||
| import lombok.Getter; | ||||||||||||||
| import lombok.NoArgsConstructor; | ||||||||||||||
|
|
||||||||||||||
| @Entity | ||||||||||||||
| @Getter | ||||||||||||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||||||
| @AllArgsConstructor | ||||||||||||||
| public class Task { | ||||||||||||||
|
|
||||||||||||||
| @Id | ||||||||||||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||||||||||
| @Column(name = "task_id", nullable = false) | ||||||||||||||
| private Long id; | ||||||||||||||
|
|
||||||||||||||
| @JoinColumn(name = "event_id") | ||||||||||||||
| @ManyToOne(fetch = FetchType.LAZY) | ||||||||||||||
| private Event event; | ||||||||||||||
|
Comment on lines
+21
to
+23
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. Many-to-One ๊ด๊ณ์์ Task์์ Event๋ก์ ์ผ๋ฐ์ ์ผ๋ก Many-to-One ๊ด๊ณ(์์ -> ๋ถ๋ชจ)์์๋ cascade๋ฅผ ์ฌ์ฉํ์ง ์๊ฑฐ๋, ๋ค์ diff๋ฅผ ์ ์ฉํ์ฌ cascade๋ฅผ ์ ๊ฑฐํ์ธ์: @JoinColumn(name = "event_id")
- @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ @ManyToOne(fetch = FetchType.LAZY)
private Event event;๐ Committable suggestion
Suggested change
๐ค Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package ita.growin.domain.user.entity; | ||
|
|
||
|
|
||
| import ita.growin.domain.event.entity.Event; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| public class User { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "user_id") | ||
| private Long id; | ||
|
|
||
| @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<Event> events = new ArrayList<>(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| spring: | ||
| config: | ||
| activate: | ||
| on-profile: "dev" | ||
| datasource: | ||
| driver-class-name: com.mysql.cj.jdbc.Driver | ||
| url: ${DEV_DB_URL} | ||
| username: ${DEV_DB_USERNAME} | ||
| password: ${DEV_DB_PASSWORD} |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,15 @@ | ||||||||||
| spring: | ||||||||||
| config: | ||||||||||
| activate: | ||||||||||
| on-profile: "local" | ||||||||||
| datasource: | ||||||||||
| driver-class-name: com.mysql.cj.jdbc.Driver | ||||||||||
| url: ${LOCAL_DB_URL} | ||||||||||
| username: ${LOCAL_DB_USERNAME} | ||||||||||
| password: ${LOCAL_DB_PASSWORD} | ||||||||||
|
|
||||||||||
| jpa: | ||||||||||
| show-sql: true | ||||||||||
| open-in-view: false | ||||||||||
| hibernate: | ||||||||||
| ddl-auto: create-drop | ||||||||||
|
Comment on lines
+14
to
+15
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.
๋ ์์ ํ ์ต์ ์ ๊ณ ๋ คํด๋ณด์ธ์:
๋ค์ diff๋ฅผ ์ ์ฉํ์ฌ ๋ ์์ ํ ์ค์ ์ผ๋ก ๋ณ๊ฒฝํ์ธ์: hibernate:
- ddl-auto: create-drop
+ ddl-auto: update๐ Committable suggestion
Suggested change
๐ค Prompt for AI Agents |
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| spring: | ||
| application: | ||
| name: growin | ||
| name: growin | ||
|
|
||
| profiles: | ||
| group: | ||
| local: "local" | ||
| dev: "dev" | ||
| test: "test" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| spring: | ||
| config: | ||
| activate: | ||
| on-profile: "test" | ||
|
|
||
| # h2 ์ฌ์ฉํ๊ธฐ? | ||
| # datasource: | ||
| # driver-class-name: com.mysql.cj.jdbc.Driver | ||
| # url: ${TEST_DB_URL} | ||
| # username: ${TEST_DB_USERNAME} | ||
| # password: ${TEST_DB_PASSWORD} |
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.
Many-to-One ๊ด๊ณ์์
CascadeType.ALL์ ์ํํฉ๋๋ค.Event์์ User๋ก์
@ManyToOne๊ด๊ณ์CascadeType.ALL์ ์ฌ์ฉํ๋ฉด Event๋ฅผ ์ญ์ ํ ๋ ์ฐ๊ด๋ User๊น์ง ์ญ์ ๋ ์ ์์ต๋๋ค. ์ด๋ ์๋ํ์ง ์์ ๋ฐ์ดํฐ ์์ค์ ์ด๋ํ ์ ์์ต๋๋ค.์ผ๋ฐ์ ์ผ๋ก Many-to-One ๊ด๊ณ์์๋
CascadeType.PERSIST์CascadeType.MERGE๋ง ์ฌ์ฉํ๊ฑฐ๋, cascade๋ฅผ ์์ ํ ์ ๊ฑฐํ๋ ๊ฒ์ด ์์ ํฉ๋๋ค.๋ค์ diff๋ฅผ ์ ์ฉํ์ฌ cascade๋ฅผ ์ ๊ฑฐํ์ธ์:
๐ค Prompt for AI Agents