-->
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.  [ 2 posts ] 
Author Message
 Post subject: pojo manipulation impacted by -access- mapping attribute?
PostPosted: Wed May 18, 2005 12:37 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
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>

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 19, 2005 11:05 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Please disregard this post.

I was touching the association collection in the getter method, which was causing a problem when hibernate was loading the object.

_________________
Vincent Giguère
J2EE Developer


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

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.