Board - @BatchSize
페이지 정보
작성자 관리자 작성일 24-06-29 09:56 조회 100 댓글 0본문
package web.domain;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.BatchSize;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import lombok.*;
@Entity
@Data
@ToString(exclude = "imageSet")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name= "board")
public class Board extends BaseEntity {
@Id // primary key
@GeneratedValue(strategy = GenerationType.IDENTITY) // auto_increment
private Long bno;
@Column(length = 255, nullable = false) //칼럼의 저장 길이, null 허용 여부
private String title;
@Column(columnDefinition = "TEXT", nullable = false)
private String content;
@Column(length = 20, nullable = false)
private String writer;
//제목, 내용만 수정
public void change(String title, String content) {
this.title = title;
this.content = content;
}
@OneToMany(
mappedBy = "board", //BoardImage의 board변수
cascade = {CascadeType.ALL},
fetch = FetchType.LAZY, //지연 로딩
orphanRemoval = true
)
@Builder.Default
@BatchSize(size = 20) //5,10,20 값 테스트 결과 콘솔에서 확인
private Set<BoardImage> imageSet = new HashSet();
public void addImage(String uuid, String fileName) {
BoardImage boardImage = BoardImage.builder()
.uuid(uuid)
.fileName(fileName)
.board(this)
.ord(imageSet.size())
.build();
imageSet.add(boardImage);
}
public void clearImage() {
imageSet.forEach(boardImage -> boardImage.changeBoard(null));
this.imageSet.clear();
}
}
댓글목록 0
등록된 댓글이 없습니다.