-
Notifications
You must be signed in to change notification settings - Fork 45
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
1단계 - OneToMany (FetchType.EAGER) #128
base: tmddnrdl333
Are you sure you want to change the base?
Changes from all commits
3a6d726
96a28c5
c9e77a1
31481a2
ec3710c
9f90996
1931b4a
dddd02a
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,40 @@ | ||
package example.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "orders") | ||
public class Order { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String orderNumber; | ||
@OneToMany(fetch = FetchType.EAGER) | ||
@JoinColumn(name = "order_id", referencedColumnName = "order_id") | ||
private List<OrderItem> orderItems; | ||
|
||
public String getOrderNumber() { | ||
return orderNumber; | ||
} | ||
|
||
public void setOrderNumber(String orderNumber) { | ||
this.orderNumber = orderNumber; | ||
} | ||
|
||
// public List<OrderItem> getOrderItems() { | ||
// return orderItems; | ||
// } | ||
// | ||
// public void setOrderItems(List<OrderItem> orderItems) { | ||
// this.orderItems = orderItems; | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package example.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name = "order_items") | ||
public class OrderItem { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String product; | ||
private Integer quantity; | ||
@Column(name = "order_id") | ||
private Long orderId; | ||
|
||
public String getProduct() { | ||
return product; | ||
} | ||
|
||
public void setProduct(String product) { | ||
this.product = product; | ||
} | ||
|
||
public Integer getQuantity() { | ||
return quantity; | ||
} | ||
|
||
public void setQuantity(Integer quantity) { | ||
this.quantity = quantity; | ||
} | ||
|
||
public Long getOrderId() { | ||
return orderId; | ||
} | ||
|
||
public void setOrderId(Long orderId) { | ||
this.orderId = orderId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package persistence.sql.component; | ||
|
||
import persistence.sql.NameUtils; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class ColumnInfo { | ||
private TableInfo tableInfo; | ||
private Field columnField; | ||
|
||
private ColumnInfo(TableInfo tableInfo, Field field) { | ||
this.tableInfo = tableInfo; | ||
this.columnField = field; | ||
} | ||
|
||
public static ColumnInfo of(TableInfo tableInfo, Field columnField) { | ||
return new ColumnInfo(tableInfo, columnField); | ||
} | ||
|
||
public TableInfo getTableInfo() { | ||
return tableInfo; | ||
} | ||
|
||
public Field getColumnField() { | ||
return columnField; | ||
} | ||
Comment on lines
+20
to
+26
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. 그런 의미에서 단순히 getter 를 이용하는것보단 좀 더 책임을 줘볼 수 있을 것 같아요 :) |
||
|
||
public String getFullName() { | ||
return tableInfo.getTableName() + "." + NameUtils.getColumnName(columnField); | ||
} | ||
Comment on lines
+28
to
+30
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.
만약 SQL 에 대한 정책이 바뀔경우, Column 정보를 제공해주는 클래스와 쿼리빌더 양쪽 다 수정이 될 가능성이 생김으로써 단일책임원칙(SRP)가 위배 될 수 있다고 생각이 들어요.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package persistence.sql.component; | ||
|
||
import java.util.List; | ||
|
||
public class Condition { | ||
private ColumnInfo columnInfo; | ||
private List<String> values; | ||
private Condition andCondition; | ||
private Condition orCondition; | ||
|
||
public ColumnInfo getColumnInfo() { | ||
return columnInfo; | ||
} | ||
|
||
public List<String> getValues() { | ||
return values; | ||
} | ||
|
||
public Condition getAndCondition() { | ||
return andCondition; | ||
} | ||
|
||
public Condition getOrCondition() { | ||
return orCondition; | ||
} | ||
|
||
public Condition(ColumnInfo columnInfo, List<String> values) { | ||
this.columnInfo = columnInfo; | ||
this.values = values; | ||
} | ||
|
||
public void setAndCondition(Condition andCondition) { | ||
this.andCondition = andCondition; | ||
} | ||
|
||
public void setOrCondition(Condition orCondition) { | ||
this.orCondition = orCondition; | ||
} | ||
} |
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.
Order
와OrderItem
클래스를 추가해주셨네요 👍다만, 기존 요구사항에는
OrderItem
클래스에는orderId
필드가 존재하지 않아요 😢실제 JPA 를 사용할 때, 부모 entity 에는 정보가 있지만 자식 entity 에는 부모 정보가 없거나 반대의 경우도 있는데요! 해당 부분을 해결하려면 어떻게 해야할까요?