Guest User

Untitled

a guest
May 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public class X {
  2. @Id
  3. private Integer id;
  4. //other properties
  5.  
  6. @OneToMany(fetch = FetchType.LAZY, mappedBy = "field")
  7. private Set<Z> childs = new HashSet<>();
  8. }
  9.  
  10. public class Z {
  11. @Id
  12. private Integer id;
  13. //other properties
  14. @Lob
  15. private byte[] file;
  16. @ManyToOne(
  17. @JoinColumn(name = "id", insertable = false, updatable = false))
  18. private X field;
  19.  
  20. public Z(Integer id) {
  21. this.id = id;
  22. }
  23.  
  24. }
  25.  
  26. @Transactional
  27. public void merge(X x) {
  28. x.getChilds().add(new Z(1));
  29. x.getChilds().add(new Z(2));
  30. entityManager.merge(x);
  31. entityManager.persist(x.getChilds());
  32. }
Add Comment
Please, Sign In to add comment