-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Dirty checking in many-to-many mapping
PostPosted: Mon Aug 26, 2013 4:39 pm 
Newbie

Joined: Mon Aug 26, 2013 4:32 pm
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.