I have a Module and a Warehouse table defined as follows:
Module.java: @ManyToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL) @JoinTable(name="warehouses_have_modules", joinColumns={@JoinColumn(name="MODULE_ID", nullable=false, updatable=false)}, inverseJoinColumns={@JoinColumn(name="WAREHOUSE_ID", nullable=false, updatable=false)}) public Set<Warehouse> getWarehouses() { return warehouses; }
Warehouse.java: @ManyToMany(fetch=FetchType.EAGER, mappedBy="warehouses", cascade=CascadeType.ALL) public Set<Module> getModules() { return modules; }
I am removing a set of warehouses from a module using hibernate template like this: public void removeWarehouses(Module module, Set<Warehouse> oldAssociation) { try { module.getWarehouses().removeAll(oldAssociation); hibernateTemplate.update(module); } catch(DataAccessException d) { logger.error("Exception while associating module with warehouse(s): "+d.getMessage()); throw d; } }
The module is getting updated properly. When I do modules.getWarehouses(), I don't see the removed warehouses which is good. However, I have a bidirectional many-to-many mapping between these two entities. Hence, when I do warehouse.getModules(), I don't expect to see the module that the warehouse was removed from. However, I still see it. Am I doing something wrong here? Doesn't dirty checking work for both the entities in this case?
thanks!
|