📌 Item Entity
- @Id = Primary Key
- @GeneratedValue = 시퀀스 적용
@Entity
@Getter @Setter
public class Item {
@Id @GeneratedValue
@Column(name = "ITEM_ID")
private long id;
private String name;
private int price;
private int stockQuantity;
}
📌 Member Entity
@Entity
@Getter @Setter
public class Member {
@Id @GeneratedValue
@Column(name = "MEMBER_ID")
private Long id;
private String name;
private Long city;
private Long street;
private Long zipcode;
}
📌 Order Entity
- 사용자(고객) 의 요청(주문) 을 담당
- Member 1명으로 N개의 Order 를 요청할 수 있다.
@Entity
@Table(name = "ORDERS")
@Getter @Setter
public class Order {
@Id @GeneratedValue
@Column(name = "ORDER_ID")
private Long id;
@Column(name = "MEMBER_ID")
private Long memberId;
private LocalDateTime orderDate;
private String status;
}
📌 Order Item Entity
@Entity
@Getter @Setter
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;
}
📌 JPA Main 기본 셋팅
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 {
tx.commit();
} catch (Exception e) {
tx.rollback();
}finally {
em.close();
emf.close();
}
}
}