HHH-10329 ClassCastException on runtime with Infinispan 8.0.1.Final
* upgraded Infinispan version to 7.2.5.Final (contains fix for ISPN-5676) * removed workaround introduced in HHH-10023 * made TypeEquivalence more robust when dealing with objects that do not belong to the type
This commit is contained in:
parent
99c1aa660f
commit
52cdb3c766
|
@ -21,12 +21,23 @@ public class TypeEquivalance implements Equivalence<Object> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode(Object o) {
|
public int hashCode(Object o) {
|
||||||
return type.getHashCode(o);
|
if (type.getReturnedClass().isInstance(o)) {
|
||||||
|
return type.getHashCode(o);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return o != null ? o.hashCode() : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object x, Object y) {
|
public boolean equals(Object x, Object y) {
|
||||||
return type.isEqual(x, y);
|
Class<?> typeClass = type.getReturnedClass();
|
||||||
|
if (typeClass.isInstance(x) && typeClass.isInstance(y)) {
|
||||||
|
return type.isEqual(x, y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (x == y) || (x != null && x.equals(y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,6 +52,12 @@ public class TypeEquivalance implements Equivalence<Object> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object x, Object y) {
|
public int compare(Object x, Object y) {
|
||||||
return type.compare(x, y);
|
Class<?> typeClass = type.getReturnedClass();
|
||||||
|
if (typeClass.isInstance(x) && typeClass.isInstance(y)) {
|
||||||
|
return type.compare(x, y);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,10 +306,6 @@ public class Caches {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V> CollectableCloseableIterable<K> keys(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
public static <K, V> CollectableCloseableIterable<K> keys(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
||||||
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
|
|
||||||
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
|
|
||||||
cache.containsKey(false);
|
|
||||||
}
|
|
||||||
// HHH-10023: we can't use keySet()
|
// HHH-10023: we can't use keySet()
|
||||||
final CloseableIterable<CacheEntry<K, Void>> entryIterable = cache
|
final CloseableIterable<CacheEntry<K, Void>> entryIterable = cache
|
||||||
.filterEntries( filter )
|
.filterEntries( filter )
|
||||||
|
@ -322,20 +318,12 @@ public class Caches {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V> CollectableCloseableIterable<V> values(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
public static <K, V> CollectableCloseableIterable<V> values(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
||||||
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
|
|
||||||
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
|
|
||||||
cache.containsKey(false);
|
|
||||||
}
|
|
||||||
// HHH-10023: we can't use values()
|
// HHH-10023: we can't use values()
|
||||||
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
|
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
|
||||||
return new CollectableCloseableIterableImpl<K, V, V>(entryIterable, Selector.VALUE);
|
return new CollectableCloseableIterableImpl<K, V, V>(entryIterable, Selector.VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V, T> CollectableCloseableIterable<T> values(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter, Converter<K, V, T> converter) {
|
public static <K, V, T> CollectableCloseableIterable<T> values(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter, Converter<K, V, T> converter) {
|
||||||
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
|
|
||||||
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
|
|
||||||
cache.containsKey(false);
|
|
||||||
}
|
|
||||||
// HHH-10023: we can't use values()
|
// HHH-10023: we can't use values()
|
||||||
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
|
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
|
||||||
return new CollectableCloseableIterableImpl<K, T, T>(entryIterable, Selector.VALUE);
|
return new CollectableCloseableIterableImpl<K, T, T>(entryIterable, Selector.VALUE);
|
||||||
|
@ -347,20 +335,12 @@ public class Caches {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V> MapCollectableCloseableIterable<K, V> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
public static <K, V> MapCollectableCloseableIterable<K, V> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter) {
|
||||||
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
|
|
||||||
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
|
|
||||||
cache.containsKey(false);
|
|
||||||
}
|
|
||||||
// HHH-10023: we can't use values()
|
// HHH-10023: we can't use values()
|
||||||
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
|
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
|
||||||
return new MapCollectableCloseableIterableImpl<K, V>(entryIterable);
|
return new MapCollectableCloseableIterableImpl<K, V>(entryIterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V, T> MapCollectableCloseableIterable<K, T> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter, Converter<K, V, T> converter) {
|
public static <K, V, T> MapCollectableCloseableIterable<K, T> entrySet(AdvancedCache<K, V> cache, KeyValueFilter<K, V> filter, Converter<K, V, T> converter) {
|
||||||
if (cache.getCacheConfiguration().transaction().transactionMode().isTransactional()) {
|
|
||||||
// Dummy read to enlist the LocalTransaction as workaround for ISPN-5676
|
|
||||||
cache.containsKey(false);
|
|
||||||
}
|
|
||||||
// HHH-10023: we can't use values()
|
// HHH-10023: we can't use values()
|
||||||
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
|
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
|
||||||
return new MapCollectableCloseableIterableImpl<K, T>(entryIterable);
|
return new MapCollectableCloseableIterableImpl<K, T>(entryIterable);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.hibernate.test.cache.infinispan.functional;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
import org.hibernate.test.cache.infinispan.functional.entities.Name;
|
import org.hibernate.test.cache.infinispan.functional.entities.Name;
|
||||||
import org.hibernate.test.cache.infinispan.functional.entities.Person;
|
import org.hibernate.test.cache.infinispan.functional.entities.Person;
|
||||||
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -63,4 +64,13 @@ public class EqualityTest extends SingleNodeTest {
|
||||||
assertEquals(expected.getName().getLastName(), person.getName().getLastName());
|
assertEquals(expected.getName().getLastName(), person.getName().getLastName());
|
||||||
assertEquals(expected.getAge(), person.getAge());
|
assertEquals(expected.getAge(), person.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@TestForIssue(jiraKey = "HHH-10329")
|
||||||
|
@Test
|
||||||
|
public void testInvalidationWithEmbeddedId() throws Exception {
|
||||||
|
Person person = new Person("John", "Brown", 33);
|
||||||
|
withTxSession(s -> s.persist(person));
|
||||||
|
withTx(() -> { cleanupCache(); return 0; });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ ext {
|
||||||
// h2Version = '1.2.145'
|
// h2Version = '1.2.145'
|
||||||
h2Version = '1.3.176'
|
h2Version = '1.3.176'
|
||||||
bytemanVersion = '2.1.2'
|
bytemanVersion = '2.1.2'
|
||||||
infinispanVersion = '7.2.1.Final'
|
infinispanVersion = '7.2.5.Final'
|
||||||
jnpVersion = '5.0.6.CR1'
|
jnpVersion = '5.0.6.CR1'
|
||||||
elVersion = '2.2.4'
|
elVersion = '2.2.4'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue