PROJECTA_BUSAN #1

aro9515·2022년 5월 11일
0
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.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.CreationTimestamp;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

import lombok.Data;

@Entity
@Data
@Table(name = "MEMBER10")

public class MemberEntity {
	@Id
	@Column(name = "USERID")
	public String userid = null;

	// 쓰기 가능, 조회 불가능
	@Column(name = "USERPW")
	@JsonProperty(access = Access.WRITE_ONLY)
	private String userpw = null;

	// 컬럼이 안만들어짐
	@Transient
	@JsonProperty(access = Access.WRITE_ONLY)
	private String userpw1 = null;

	@Column(name = "USERNAME")
	private String username = null;

	@Column(name = "USERTEL")
	private String usertel = null;

	@Column(name = "USERROLE", updatable = false)
	private String userrole = null;

	@CreationTimestamp
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
	@Column(name = "USERDATE", updatable = false)
	private Date userdate = null;

	
	// 참조가 되는 앞부분을 의미하며, 정상적으로 직렬화를 수행
	@JsonManagedReference
	@OneToMany(mappedBy = "member", fetch = FetchType.LAZY)
	@OrderBy("no asc")
	private List<BoardEntity> boardList = new ArrayList<>();
}

package com.example.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import lombok.Data;

@Data
@Entity
@Table(name = "BOARD10") // DB의 ITEM
@SequenceGenerator(name = "SEQ2", // 이 클래스에 사용하는 명칭
		sequenceName = "SEQ_BOARD10_NO", // DB의 시퀀스명
		initialValue = 1, allocationSize = 1)
public class BoardEntity {

	@Column(name = "NO") 
	@Id // 기본키
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ2")
	private Long no; // no 변수

	@Column(name = "TITLE")
	private String title;

	@Column(name = "CONTENT")
	private String content;


	@Column(name = "HIT")
	private Long hit = 1L;

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
	@CreationTimestamp // SYSDATE 와 같은 기능
	@Column(name = "REGDATE") // Item테이블의 REGDATE컬럼
	private Date regdate;

	@JsonManagedReference
	@OneToMany(mappedBy = "board", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
	private List<BoardReplyEntity> replyList = new ArrayList<>();


    // 참조가 되는 뒷부분을 의미하며, 직렬화를 수행하지 않음
	@JsonBackReference
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "USERID", referencedColumnName = "USERID")
	private MemberEntity member;
}

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.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonBackReference;

import lombok.Data;


@Data
@Entity
@Table(name = "BOARD10_REPLY")
@SequenceGenerator(name = "SEQ1", sequenceName = "SEQ_BOARD10_REPLY_NO", initialValue = 1, allocationSize = 1)

public class BoardReplyEntity {

	@Column(name = "NO")
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ1")
	private Long repno;

	@Lob
	@Column(name = "CONTENT")
	private String content;

	@JsonBackReference
	@ManyToOne
	@JoinColumn(name = "BRDNO")
	private BoardEntity board;

	
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS")
	@CreationTimestamp
	@Column(name = "REGDATE")
	private Date regdate;
}
profile
The best

0개의 댓글