Entity with EmbeddedId fails retrieve from cache after deployment reload

Description

I'm on WildFly 10, Hibernate 5.2.2 and a simple JAX-RS/JPA app with an entity like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 @Entity @Cacheable public class MyEntity implements Serializable { @EmbeddedId private MyEmbeddableId id; // other fields, hashCode, equals, getters and setters } @Embeddable public class MyEmbeddableId implements Serializable { private String foo; private String bar; // hashCode, equals, getters and setters }

All works like expected, but if I reload the app (not restarting WildFly) then on entity load I get:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String MyEmbeddableId.foo] by reflection for persistent property [MyEmbeddableId#foo] : MyEmbeddableId@33675787 at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:71) at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:58) at org.hibernate.type.ComponentType.getPropertyValue(ComponentType.java:414) at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:225) at org.hibernate.cache.infinispan.TypeEquivalance.hashCode(TypeEquivalance.java:24) at org.infinispan.commons.util.concurrent.jdk8backported.BoundedEquivalentConcurrentHashMapV8.get(BoundedEquivalentConcurrentHashMapV8.java:2427) at org.infinispan.container.DefaultDataContainer.get(DefaultDataContainer.java:188) at org.infinispan.container.EntryFactoryImpl.innerGetFromContainer(EntryFactoryImpl.java:288) at org.infinispan.container.EntryFactoryImpl.getFromContainer(EntryFactoryImpl.java:258) at org.infinispan.container.EntryFactoryImpl.wrapEntryForReading(EntryFactoryImpl.java:64) at org.infinispan.interceptors.EntryWrappingInterceptor.visitDataReadCommand(EntryWrappingInterceptor.java:132) at org.infinispan.interceptors.EntryWrappingInterceptor.visitGetKeyValueCommand(EntryWrappingInterceptor.java:123) at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:40) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:113) at org.infinispan.commands.AbstractVisitor.visitGetKeyValueCommand(AbstractVisitor.java:85) at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:40) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.locking.PessimisticLockingInterceptor.visitDataReadCommand(PessimisticLockingInterceptor.java:71) at org.infinispan.interceptors.locking.AbstractLockingInterceptor.visitGetKeyValueCommand(AbstractLockingInterceptor.java:77) at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:40) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.TxInterceptor.enlistReadAndInvokeNext(TxInterceptor.java:345) at org.infinispan.interceptors.TxInterceptor.visitGetKeyValueCommand(TxInterceptor.java:330) at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:40) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:107) at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:76) at org.infinispan.commands.AbstractVisitor.visitGetKeyValueCommand(AbstractVisitor.java:85) at org.infinispan.commands.read.GetKeyValueCommand.acceptVisitor(GetKeyValueCommand.java:40) at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:336) at org.infinispan.cache.impl.CacheImpl.get(CacheImpl.java:411) at org.infinispan.cache.impl.CacheImpl.get(CacheImpl.java:403) at org.infinispan.cache.impl.AbstractDelegatingCache.get(AbstractDelegatingCache.java:286) at org.hibernate.cache.infinispan.access.InvalidationCacheAccessDelegate.get(InvalidationCacheAccessDelegate.java:61) at org.hibernate.cache.infinispan.entity.ReadOnlyAccess.get(ReadOnlyAccess.java:44) at org.hibernate.engine.internal.CacheHelper.fromSharedCache(CacheHelper.java:32) at org.hibernate.event.internal.DefaultLoadEventListener.getFromSharedCache(DefaultLoadEventListener.java:651) at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:595) at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:462) at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219) at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:278) at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:121) at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89) at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1218) at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1101) at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:639) at org.hibernate.type.EntityType.resolve(EntityType.java:431) at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:151) at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:125) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1146) at org.hibernate.loader.Loader.processResultSet(Loader.java:1005) at org.hibernate.loader.Loader.doQuery(Loader.java:943) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:349) at org.hibernate.loader.Loader.doList(Loader.java:2615) at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2460) at org.hibernate.loader.Loader.list(Loader.java:2422) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1458) at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1426) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1398) ... 120 more Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field MyEmbeddableId.foo to MyEmbeddableId

If I restart WildFly, it works again. Also, if I disable caching all works fine also after deployment reload.

Debugging, I've found that in org.hibernate.property.access.spi.GetterFieldImpl.get, after WildFly restart we have:

1 2 3 4 Class fieldDeclaringClass = field.getDeclaringClass(); Class ownerClass = owner.getClass(); fieldDeclaringClass.getName().equals(ownerClass.getName()) == true; fieldDeclaringClass.isAssignableFrom(ownerClass) == true;

and after deployment reload:

1 2 3 4 Class fieldDeclaringClass = field.getDeclaringClass(); Class ownerClass = owner.getClass(); fieldDeclaringClass.getName().equals(ownerClass.getName()) == true; fieldDeclaringClass.isAssignableFrom(ownerClass) == false; // !!!

I don't know how this can happen, two classes with the same name which are not the same class.

Environment

WildFly 10

Status

Assignee

Unassigned

Reporter

Giovanni Lovato

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.2

Priority

Major