Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- public class User {
- //...
- @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
- private List<Note> notes = new ArrayList<>();
- //...
- public void addNotes(Note... notes) {
- for (Note note : notes) {
- note.setUser(this);
- this.notes.add(note);
- }
- }
- }
- @Entity
- public class Note {
- //...
- @ManyToOne
- private User user;
- //...
- }
- User user = new User(...);
- user.addNotes(new Note(...), new Note(...));
- userRepo.save(user);
Add Comment
Please, Sign In to add comment