Object references go null when using ObjectCacheDefaultImpl

Andrew Fortier <[email protected]>
Newsgroups gmane.comp.jakarta.ojb.user
Message-ID <[email protected]>
Hi all,

I've been chasing down a bug that has been rearing it's head every now 
and again. Hopefully someone on this list has an idea of what might be 
going on.

Occasionally an reference from one object to another will null out 
spontaneously. Example: A User object has a reference to a UserRole 
object (mapped by a userRoleId field in the User table). Occasionally, 
calls to user.getUserRole() will return null even though there is an 
associated UserRole object in the database (in both the UserRole table 
and as an id in the User table).

Thus far this has only happened when caching is enabled. We generally 
use the following settings:

<object-cache class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
    <attribute attribute-name="timeout" attribute-value="900"/>
    <attribute attribute-name="autoSync" attribute-value="true"/>
    <attribute attribute-name="cachingKeyType" attribute-value="0"/>
    <attribute attribute-name="useSoftReferences" attribute-value="true"/>
</object-cache>
(Note: it happens more frequently if the timeout is set to ~45 seconds)

The problem seems to happen only if there are two Users logged into the 
web-app at the same time, and only if they are accessing the same 
project. It should be noted that the setUserRole() method is called only 
once in the entire application code, when the user registers. There is 
really no way that method is being called when the property is nulled out.

Final note: The UserRole objects are all defined statically (e.g. public 
UserRole ADMIN = new UserRole("Administrator",ADMIN_ID); ) but are 
persisted in the database as well.

Thanks for any input! If this is happening in your app as well perhaps 
we can exchange info to help narrow down possible causes.

-= Andrew Fortier
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.