Skip to content

Commit

Permalink
HHH-10329 ClassCastException on runtime with Infinispan 8.0.1.Final
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rvansa authored and galderz committed Mar 11, 2016
1 parent 99c1aa6 commit 52cdb3c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ public TypeEquivalance(Type type) {

@Override
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
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
Expand All @@ -41,6 +52,12 @@ public boolean isComparable(Object o) {

@Override
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,6 @@ public static <K, V> CollectableCloseableIterable<K> keys(AdvancedCache<K, V> ca
}

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()
final CloseableIterable<CacheEntry<K, Void>> entryIterable = cache
.filterEntries( filter )
Expand All @@ -322,20 +318,12 @@ public static <K, V> CollectableCloseableIterable<V> values(AdvancedCache<K, V>
}

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()
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
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) {
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()
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
return new CollectableCloseableIterableImpl<K, T, T>(entryIterable, Selector.VALUE);
Expand All @@ -347,20 +335,12 @@ public static <K, V> MapCollectableCloseableIterable<K, V> entrySet(AdvancedCach
}

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()
final CloseableIterable<CacheEntry<K, V>> entryIterable = cache.filterEntries(filter);
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) {
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()
final CloseableIterable<CacheEntry<K, T>> entryIterable = cache.filterEntries(filter).converter(converter);
return new MapCollectableCloseableIterableImpl<K, T>(entryIterable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.hibernate.stat.Statistics;
import org.hibernate.test.cache.infinispan.functional.entities.Name;
import org.hibernate.test.cache.infinispan.functional.entities.Person;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;

import java.util.List;
Expand Down Expand Up @@ -63,4 +64,13 @@ private static void assertPersonEquals(Person expected, Person person) {
assertEquals(expected.getName().getLastName(), person.getName().getLastName());
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; });
}
}
2 changes: 1 addition & 1 deletion libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
// h2Version = '1.2.145'
h2Version = '1.3.176'
bytemanVersion = '2.1.2'
infinispanVersion = '7.2.1.Final'
infinispanVersion = '7.2.5.Final'
jnpVersion = '5.0.6.CR1'
elVersion = '2.2.4'

Expand Down

0 comments on commit 52cdb3c

Please sign in to comment.