-
Type:
Bug
-
Resolution: Fixed
-
Priority:
High
-
Affects Version/s: 2.8
-
Component/s: None
-
None
The new reverse mapping for InternalUserAttributes to InternalUser added in CWD-4016 causes problems with Hibernate's caches, because we aren't explicitly updating the user's attributes in the hibernate mapped entity, which Hibernate uses to populate/update its caches. The same thing applies for groups.
Problematic hibernate definition added in InternalUser.hbm.xml:
<class name="com.atlassian.crowd.model.user.InternalUser" table="cwd_user" lazy="true">
<!-- snipped out irrelevant details -->
<set name="attributes" lazy="true" inverse="true">
<key column="user_id" not-null="true"/>
<one-to-many class="com.atlassian.crowd.model.user.InternalUserAttribute"/>
</set>
</class>
This means that when we create or update an InternalUserAttribute for a given user then it has to be added to InternalUser.attributes. For example:
private void addAttribute(InternalUser user, String attributeName, String attributeValue)
{
InternalUserAttribute attribute = new InternalUserAttribute(user, attributeName, attributeValue);
session().save(attribute);
// 2 lines below are what we need to do now
user.attributes.add(attribute)
session().save(user);
}
In theory this doesn't actually save to the database; it just updates hibernate's caches. Of course we need to do it in all places that we modify a user's (or group's) attributes.
Consequences of not doing so are that hibernate will give different views onto user attributes depending on how you ask the question; i.e. inconsistent data.
Reported by bryan.turner after upgrading Stash to the latest Crowd & seeing strange behaviour under load.