Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class X {
- @Id
- private Integer id;
- //other properties
- @OneToMany(fetch = FetchType.LAZY, mappedBy = "field")
- private Set<Z> childs = new HashSet<>();
- }
- public class Z {
- @Id
- private Integer id;
- //other properties
- @Lob
- private byte[] file;
- @ManyToOne(
- @JoinColumn(name = "id", insertable = false, updatable = false))
- private X field;
- public Z(Integer id) {
- this.id = id;
- }
- }
- @Transactional
- public void merge(X x) {
- x.getChilds().add(new Z(1));
- x.getChilds().add(new Z(2));
- entityManager.merge(x);
- entityManager.persist(x.getChilds());
- }
Add Comment
Please, Sign In to add comment