@Entity
@Table(name = "folder")
@IdClass(FolderId.class)
public class Folder {
@Id
@Column(name = "tenantId", updatable = false, nullable = false)
private String tenantId;
@Id
@SequenceGenerator(name = "folder_id_seq", sequenceName = "folder_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "folder_id_seq")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Folder> children;
@ManyToOne
@JoinTable(name = "folderTree",
joinColumns = {
@JoinColumn(name = "tenantId", referencedColumnName = "tenantId"),
@JoinColumn(name = "parentId", referencedColumnName = "id")
},
inverseJoinColumns = {
@JoinColumn(name = "tenantId", referencedColumnName = "tenantId"),
@JoinColumn(name = "folderId", referencedColumnName = "id")
}
)
private Folder parent;
}