I have an object that can be child of itself, in a way that it generates a tree of objects, for exemple an article could be the composition of many other articles, so i'm using a @ManyToOne
to relate the article to itself, the tree of 4 articles should look like this:
article A (lvl 1) --> article B (lvl 2) --> article C (lvl 3) --> article D (lvl 4)
@Entity
public class Article implements Serializable {
@ManyToOne
@JoinColumn(name = "article_father", referencedColumnName = "id")
private Article articleFather;
@Column(name = "level")
private Integer level;
}
Now my problem is when i want to remove the father of article B, is there any way with jpa
to refresh the levels of article B and C and D, so that i would have two trees :
If I right you need tree.
My example:
level - count of parents