Hi,
I have standard pojo association manipulation methods that are unfortunately dependant on the 'access' attribute on the association mapping.
If the attribute is access="field", nothing happens when the transaction commits, but if i set it to access="property", then everything works fine.
I have read the documentation on the access flag, and my understanding is that it only defines wether hibernate should access the field directly or through an accessor method. I am wondering why this impacts standard pojo manipulation like the one shown below.
The context is:
I have two classes: SecurityAcl and SecurityRole with a many-to-many relationship. Persisting changes made to their relation does not work if the property access is set to field, but works if it is set to property.
I want to reset the relation between an ACL and a Role. Hence, I execute the following code within the scope of a session:
Code:
dao.reassociate(acl);
acl.getAssociatedRoles().clear();
acl.associateRoles(roles);
dao.save(acl);
...
PS - The dao object roughly delegates dao.reassociate to session.lock and dao.save to session.saveOrUpdate
Here is the code of the two methods being called.
Code:
public Collection getAssociatedRoles() {
return this.associatedRoles;
}
public void associateRoles(Collection roles) {
this.associatedRoles.addAll(roles);
}
public void associateRole(SecurityRole role) {
this.associatedRoles.add(role);
}
Thanks in advance for spending the time to tell me why hibernate is behaving this way.
Vincent
Hibernate version: 3.0.2
Mapping documents:The association mapping
Code:
<set name="associatedRoles" table="security_role_to_acl" lazy="true" cascade="save-update" access="property">
<key column="acl_id"/>
<many-to-many class="SecurityRoleImpl" column="role_id"/>
</set>