berryberrybin / board-project

0 stars 0 forks source link

생성자 VS 정적 팩터리 메서드 #3

Open berryberrybin opened 1 year ago

berryberrybin commented 1 year ago
@Getter
@Setter
@Entity
@Table(name = "comment_like")
@NoArgsConstructor
public class CommentLike {

    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "comment_like_id", unique = true, updatable = false, nullable = false, columnDefinition = "BINARY(16)")
    private UUID commentLikeId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "comment_id")
    private Comment comment;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;

    public CommentLike(User user, Comment comment) {
        this.user = user;
        this.comment = comment;
    }

    // 생성자 대신 정적 팩터리 메서드 사용시 코드 
    // private CommentLike(User user, Comment comment){
    //  this.user = user;
    //  this.comment = comment;
    // }
    //
    // public static CommentLike createCommentLike(User user, Comment comment){
    //  return new CommentLike(user, comment);
    // }
}
berryberrybin commented 1 year ago