HHH-7502 - Problems with multi-tenancy and 2nd level cache

This commit is contained in:
Steve Ebersole 2012-08-06 18:26:22 -05:00
parent 7f10972048
commit 45118e729d
1 changed files with 23 additions and 14 deletions

View File

@ -30,11 +30,11 @@ import org.hibernate.internal.util.compare.EqualsHelper;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
* Allows multiple entity classes / collection roles to be * Allows multiple entity classes / collection roles to be stored in the same cache region. Also allows for composite
* stored in the same cache region. Also allows for composite
* keys which do not properly implement equals()/hashCode(). * keys which do not properly implement equals()/hashCode().
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole
*/ */
public class CacheKey implements Serializable { public class CacheKey implements Serializable {
private final Serializable key; private final Serializable key;
@ -64,13 +64,25 @@ public class CacheKey implements Serializable {
this.type = type; this.type = type;
this.entityOrRoleName = entityOrRoleName; this.entityOrRoleName = entityOrRoleName;
this.tenantId = tenantId; this.tenantId = tenantId;
this.hashCode = type.getHashCode( key, factory ); this.hashCode = calculateHashCode( type, factory );
} }
@Override private int calculateHashCode(Type type, SessionFactoryImplementor factory) {
public String toString() { int result = type.getHashCode( key, factory );
// Mainly for OSCache result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);
return entityOrRoleName + '#' + key.toString();//"CacheKey#" + type.toString(key, sf); return result;
}
public Serializable getKey() {
return key;
}
public String getEntityOrRoleName() {
return entityOrRoleName;
}
public String getTenantId() {
return tenantId;
} }
@Override @Override
@ -93,12 +105,9 @@ public class CacheKey implements Serializable {
return hashCode; return hashCode;
} }
public Serializable getKey() { @Override
return key; public String toString() {
// Mainly for OSCache
return entityOrRoleName + '#' + key.toString();//"CacheKey#" + type.toString(key, sf);
} }
public String getEntityOrRoleName() {
return entityOrRoleName;
}
} }