Hi. I just noticed that I loose associated lazy loaded many-to-many collection if I merged an updated entity. Am I missing something? I can't quite figure exactly how cascading works...
OpenJPA 2.1.1, enhanced by PCEnhancer. Nothing funny in persistence.xml (listerally, just list of classes), no orm file. code: E_App app = em.find(E_App.class, key); app.setDescription(desc); app.setPurchased(false); // if I add app.getCategories() here, they don't get removed. em.merge(app); // transaction commits // after this point "app", when reloaded, has empty "categories" // I expect them to not get reset, since they are LAZY, and I'm not touching them. entity: @Entity @Table(name = "apps") @Access(AccessType.FIELD) public class E_App { @Id @Column(name="package_name") private String packageName; // ... @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinTable(name = "app_cat_map", joinColumns = @JoinColumn(name = "package_name"), inverseJoinColumns = @JoinColumn(name = "category_id")) private Collection<E_Category> categories; // ... } @Entity @Table(name="categories") public class E_Category { @Id @GeneratedValue(generator = "categoriesSeq", strategy = GenerationType.SEQUENCE) private long id; @ManyToMany(fetch = FetchType.LAZY, mappedBy = "categories") private Collection<E_App> apps; // ... } Any help is greatly appreciated. Thanks, Pawel.