Created
June 5, 2022 07:45
-
-
Save chongma/ac7a2adec120bee78e597a09f1e4b6a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| public class ChildNotWorks { | |
| @Id | |
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| private Long id; | |
| private int order; | |
| @ManyToOne(fetch = FetchType.LAZY) | |
| private Parent parent; | |
| public ChildNotWorks() { | |
| super(); | |
| } | |
| public ChildNotWorks(Parent parent, int order) { | |
| super(); | |
| this.parent = parent; | |
| this.order = order; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| public class ChildWorks { | |
| @Id | |
| @GeneratedValue(strategy = GenerationType.SEQUENCE) | |
| private Long id; | |
| private int order; | |
| @ManyToOne(fetch = FetchType.LAZY) | |
| private Parent parent; | |
| public ChildWorks() { | |
| super(); | |
| } | |
| public ChildWorks(Parent parent, int order) { | |
| super(); | |
| this.parent = parent; | |
| this.order = order; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void doTheThing() { | |
| Parent parent = new Parent(); | |
| // These seem to have sequential id numbers | |
| List<ChildWorks> childsWorks = new ArrayList<>(); | |
| childsWorks.add(new ChildWorks(parent, 1)); | |
| childsWorks.add(new ChildWorks(parent, 2)); | |
| childsWorks.add(new ChildWorks(parent, 3)); | |
| parent.setChildsWorks(childsWorks); | |
| // These id numbers are out of order | |
| List<ChildNotWorks> childsNotWorks = new ArrayList<>(); | |
| childsNotWorks.add(new ChildNotWorks(parent, 1)); | |
| childsNotWorks.add(new ChildNotWorks(parent, 2)); | |
| childsNotWorks.add(new ChildNotWorks(parent, 3)); | |
| parent.setChildsNotWorks(childsNotWorks); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| public class Parent { | |
| @Id | |
| private int id; | |
| @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) | |
| private List<ChildWorks> childsWorks; | |
| @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) | |
| private List<ChildNotWorks> childsNotWorks; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment