파일명 ProductEntity.java
package com.example.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.format.annotation.DateTimeFormat;
import lombok.Data;
@Data
@Entity
@Table(name = "PRODUCT")
@SequenceGenerator(
name = "SEQ3",
sequenceName = "SEQ_PRODUCT_NO",
allocationSize = 1,
initialValue=1001)
public class ProductEntity {
@Id
@GeneratedValue(generator = "SEQ3", strategy = GenerationType.SEQUENCE)
Long no;
@Column(length = 250)
String name;
Long price;
@Lob
@Column(nullable = true)
byte[] imagedata;
String imagename;
String imagetype;
Long imagesize=0L;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
@UpdateTimestamp
Date uptdate;
@JsonBackReference
@OneToMany(mappedBy = "product")
List<ProductCountEntity> list = new ArrayList<>();
}
파일명 ProductCountEntity.java
package com.example.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.format.annotation.DateTimeFormat;
import lombok.Data;
@Data
@Entity
@Table(name = "PRODUCTCOUNT")
@SequenceGenerator(
name = "SEQ_PC",
sequenceName = "SEQ_PRODUCTCOUNT_NO",
allocationSize = 1,
initialValue=1)
public class ProductCountEntity {
@Id
@GeneratedValue(generator = "SEQ_PC", strategy = GenerationType.SEQUENCE)
Long no;
Long cnt; // 입고시 10, 출고시 -5
@Column(length = 10)
String type; // 입고는 I, 출고는 O
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
@UpdateTimestamp
Date regdate; // 등록일
@ManyToOne // 외래키
@JoinColumn(name = "PRODUCT_NO", referencedColumnName = "NO")
ProductEntity product;
}
파일명 ProductViewEntity.java
package com.example.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.annotation.Immutable;
import lombok.Data;
@Immutable // view인경우 추가, 읽기만 가능 findBy..만
@Entity
@Data
@Table(name="PRODUCT_VIEW")
public class ProductViewEntity {
@Id
@Column(name = "no")
Long no;
@Column(length = 250)
String name;
Long price;
Long cnt;
}