Re: Object references go null when using ObjectCacheDefaultImpl

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

Andrew Fortier wrote:
> 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.
> 

1. Keep in mind that ObjectCacheDefaultImpl is a shared cache, thus it 
could happen that different user operate on the same object instance.
http://db.apache.org/ojb/docu/guides/objectcache.html#ObjectCacheDefaultImpl

2. If you are using versions <1.0.2 it can happen that partially 
materialized objects (e.g. without populated reference) are requested by 
other threads (fixed in 1.0.2).

Did you tried to use the two-level cache? Same issue?
http://db.apache.org/ojb/docu/guides/objectcache.html#ObjectCacheTwoLevelImpl

regards,
Armin

> 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
> 
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
>
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.