我在WildFly 10,Hibernate 5.2.2和一个简单的JAX-RS / JPA应用程序上使用这样的实体:
@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
}
所有工作都像预期的那样,但如果我重新加载应用程序(不重新启动WildFly),那么在实体加载中我得到:
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
如果我重新启动WildFly,它会再次运行。此外,如果我禁用缓存,部署重新加载后也可以正常工作。
我做错了吗?这是Hibernate或WildFly中的错误吗?