업무 중 SelfJoin하는 엔티티 코드를 바로 이해하지 못해 간략히 study 코드를 만들어보았다.
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
public class Category {
@Id
private String id;
private String name;
private Integer level;
private Integer sequence;
@Column(name = "parent_id")
private String parentId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id", referencedColumnName = "id", insertable = false, updatable = false)
private Category parent;
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
private List<Category> children = new ArrayList<>();
@Override
public String toString() {
return "Category{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", level=" + level +
", sequence=" + sequence +
", parentId='" + parentId + '\'' +
'}';
}
}