I am using hibernate from 3.2.0 branch and jboss-cache-1.4.0.ga.
I have discovered that the cache throws NPE when we are trying to
remove unexciting data. The methods "destroy" and "writeLoad" do so.
I just have analysed the existing code and found, that method "remove"
do a check before calling "remove". In this method the key remove if
"cache.get" returns not null. So I applied the same approach in
methods "destroy" and "writeLoad".
My test now works. But I do not sure. Are this versions of hibernate
and jbossCache compatible? Can we use OptimisticeTreeCache or it is
under construction?
Index: src/org/hibernate/cache/OptimisticTreeCache.java
===================================================================
--- src/org/hibernate/cache/OptimisticTreeCache.java (revision 10638)
+++ src/org/hibernate/cache/OptimisticTreeCache.java (working copy)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.cache;
+import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -70,13 +71,15 @@
public void writeLoad(Object key, Object value, Object currentVersion) {
try {
+ if ( cache.get( new Fqn( regionFqn, key ), ITEM ) != null ) {
+ Option option = new Option();
+ option.setFailSilently( true );
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
+ }
+
Option option = new Option();
option.setFailSilently( true );
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
-
- option = new Option();
- option.setFailSilently( true );
DataVersion dv = ( source != null && source.isVersioned() )
? new DataVersionAdapter( currentVersion, currentVersion, source.getVersionComparator(), source.toString() )
: NonLockingDataVersion.INSTANCE;
@@ -172,11 +175,15 @@
public void destroy() throws CacheException {
try {
- Option option = new Option();
- option.setCacheModeLocal( true );
- option.setFailSilently( true );
- option.setDataVersion( NonLockingDataVersion.INSTANCE );
- cache.remove( regionFqn, option );
+ // if ( cache.get(regionFqn) != null ) {
+ Method getMethod = org.jboss.cache.TreeCache.class.getMethod("get", new Class[] { Fqn.class });
+ if (getMethod.invoke(cache, new Object[] { regionFqn }) != null) {
+ Option option = new Option();
+ option.setCacheModeLocal( true );
+ option.setFailSilently( true );
+ option.setDataVersion( NonLockingDataVersion.INSTANCE );
+ cache.remove( regionFqn, option );
+ }
}
catch( Exception e ) {
throw new CacheException( e );
_______________________________________________
hibernate-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/hibernate-dev