에러메시지:
org.hibernate.assertionfailure null identifier
@Setter @Getter @AllArgsConstructor @NoArgsConstructor
@Entity
@Table(name="review")
@SequenceGenerator(
name = "REVIEW_SEQ_GENERATOR",
sequenceName = "REVIEW_SEQ", //매핑할 데이터베이스 시퀀스 이름
initialValue = 1, allocationSize = 1)
@DynamicInsert
@DynamicUpdate
public class Review {
@Id
@JoinColumn(name = "num")
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "REVIEW_SEQ_GENERATOR")
private Long rNum;
@ManyToOne
// (
// cascade = {
// CascadeType.PERSIST,
// CascadeType.MERGE //머지쓰면 update된다. 즉 유저 한명당 리뷰 하나만...가능..!
// })
@JoinColumn(name = "user_id")
private User user;
@Column(name = "sort")
private int sort;
@Column(name = "title")
private String title;
@Column(name = "content")
private String content;
@Column(name = "created_date")
private LocalDateTime createdDate;
@Column(name = "stars")
private float stars;
@OneToOne
@JoinColumns({@JoinColumn(name = "order_num"),
@JoinColumn(name = "prod_num")})
private OrderDetail orderDetail;
@OneToOne(mappedBy = "review")
private BestReview bestReview;
}
@Setter @Getter @AllArgsConstructor @NoArgsConstructor
@Entity
@Table(name="best_review")
@DynamicInsert
@DynamicUpdate
public class BestReview {
@Id
@Column(name = "review_num")
private Long rNum;
@MapsId
@OneToOne
@JoinColumn(name = "review_num")
private Review review;
@Column(name = "created_date")
private LocalDateTime createdDate;
}
문제는, 종속관계인 BestReview 쪽에 CascadeType.ALL을 지정해주지 않아서 rNum이 null로 들어가고 있었다.
따라서,
@Setter @Getter @AllArgsConstructor @NoArgsConstructor
@Entity
@Table(name="best_review")
@DynamicInsert
@DynamicUpdate
public class BestReview {
@Id
@Column(name = "review_num")
private Long rNum;
@MapsId
@OneToOne(cascade = CascadeType.ALL) //<-- 요고!! 필수
@JoinColumn(name = "review_num")
private Review review;
@Column(name = "created_date")
private LocalDateTime createdDate;
}