【问题标题】:Getting java.lang.ClassCastException with all the Hibernate entity classes for ehcache使用 ehcache 的所有 Hibernate 实体类获取 java.lang.ClassCastException
【发布时间】:2016-11-18 00:31:37
【问题描述】:

我使用的是“1.7.0_79”版本。 得到以下异常

2016-11-17 16:42:54,127 : ERROR: net.sf.ehcache.store.disk.DiskStorageFactory - Disk Write of

data_member_keys 失败: java.lang.ClassCastException:无法转换 sun.reflect.GeneratedSerializationConstructorAccessor1 到 sun.reflect.SerializationConstructorAccessorImpl 在 sun.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:113) 在enter code heresun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:331) 在 java.io.ObjectStreamClass.getSerializableConstructor(ObjectStreamClass.java:1376) 在 java.io.ObjectStreamClass.access$1500(ObjectStreamClass.java:72) 在 java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:493) 在 java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:468) 在 java.security.AccessController.doPrivileged(本机方法) 在 java.io.ObjectStreamClass.(ObjectStreamClass.java:468) 在 java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:365) 在 java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1133) 在 java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347) 在 net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97) 在 net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:405) 在 net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:384) 在 net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:485) 在 net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1088) 在 net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1072) 在 java.util.concurrent.FutureTask.run(FutureTask.java:262) 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) 在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 在 java.lang.Thread.run(Thread.java:745)

jpa.xml

<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.abc.xyz" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.hbm2ddl.auto">validate</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
                <prop key="hibernate.connection.isolation">2</prop>
                <!-- should be turned off in production -->
                <prop key="hibernate.generate_statistics">false</prop>

                <!-- This is the provider for Ehcache provided by Hibernate, using the "old" SPI -->
                <prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
                <prop key="hibernate.cache.use_second_level_cache">true"</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>


            </props>
        </property>
    </bean>

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>

<ehcache>
    <diskStore path="java.io.tmpdir"/>

    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
           maxElementsInMemory="50000"
           eternal="true"
           overflowToDisk="true"/>

    <cache name="org.hibernate.cache.internal.StandardQueryCache"
           maxElementsInMemory="50000"
           eternal="false"
           timeToIdleSeconds="120"
           timeToLiveSeconds="120"
           overflowToDisk="true"
           diskPersistent="false"
               diskExpiryThreadIntervalSeconds="120"
           memoryStoreEvictionPolicy="LRU"
            />

    <defaultCache
            maxElementsInMemory="50000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />

</ehcache>

有没有人知道这个问题的解决方案。

【问题讨论】:

  • 欢迎来到 Stack Overflow!请发布您正在使用的导致问题的代码。

标签: java hibernate jpa ehcache


【解决方案1】:

您遇到了类加载器问题。

发生此错误的唯一方法是,如果您当前正在序列化的类来自一个看不到当前序列化程序使用的 SerializationConstructorAccessorImpl 的类加载器。

如果不知道您遇到此错误的环境,我无法提供更多信息。

我猜你使用的是 JDK 1.6。

【讨论】:

  • 不,我使用的是“1.7.0_79”版本。
猜你喜欢
  • 2015-09-17
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-08
  • 1970-01-01
  • 2021-05-17
相关资源
最近更新 更多