Hello,
I get an NotSerializableException when trying to use 2nd level cahce using ehcache with offheap overflow. Hibernate is using ProxyFactoryFactoryImpl for using a composite-id inside CoverRuleMD. It looks like hibernate is trying to serialize the composite-id into a cache which fails it is not Serializable object. Notice: it is not the POJO who contains the javaassist proxy, it is a composite-id object with javaassist proxy which is failing in the cache.
Is there any option to disable creating Proxy for composite ID, or to mark ProxyFactoryFactoryImpl as transient?
Thanks
Code:
Exception:
Caused by: net.sf.ehcache.CacheException: Failure while encoding key com.idi.policy.premium.common.vo.ifc.CoverRuleMD#com.idi.policy.premium.common.vo.ifc.CoverRuleMD_$$_javassist_41@26421488
at net.sf.ehcache.store.offheap.portability.EhcacheKeyPortability.encode(EhcacheKeyPortability.java:44)
at net.sf.ehcache.store.offheap.portability.EhcacheKeyPortability.encode(EhcacheKeyPortability.java:24)
at com.terracottatech.offheapstore.storage.PortabilityBasedStorageEngine.writeMapping(PortabilityBasedStorageEngine.java:55)
at com.terracottatech.offheapstore.OffHeapHashMap.tryWriteEntry(OffHeapHashMap.java:656)
at com.terracottatech.offheapstore.OffHeapHashMap.writeEntry(OffHeapHashMap.java:640)
at com.terracottatech.offheapstore.OffHeapHashMap.put(OffHeapHashMap.java:391)
at com.terracottatech.offheapstore.AbstractLockedOffHeapHashMap.put(AbstractLockedOffHeapHashMap.java:132)
at com.terracottatech.offheapstore.AbstractOffHeapClockCache.putPinned(AbstractOffHeapClockCache.java:263)
at com.terracottatech.offheapstore.concurrent.AbstractConcurrentOffHeapCache.putPinned(AbstractConcurrentOffHeapCache.java:185)
at net.sf.ehcache.store.offheap.OffHeapStore.putFaulted(OffHeapStore.java:417)
at net.sf.ehcache.store.CacheStore$2.call(CacheStore.java:143)
at net.sf.ehcache.store.CacheStore$2.call(CacheStore.java:140)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.get(OnHeapCachingTier.java:309)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier$Fault.access$200(OnHeapCachingTier.java:283)
at net.sf.ehcache.store.cachingtier.OnHeapCachingTier.get(OnHeapCachingTier.java:166)
at net.sf.ehcache.store.CacheStore.put(CacheStore.java:140)
at net.sf.ehcache.Cache.putInternal(Cache.java:1500)
at net.sf.ehcache.Cache.put(Cache.java:1426)
at net.sf.ehcache.Cache.put(Cache.java:1391)
at net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion.put(EhcacheTransactionalDataRegion.java:141)
... 93 more
Caused by: java.io.NotSerializableException: org.hibernate.bytecode.javassist.ProxyFactoryFactoryImpl$1
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1474)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at net.sf.ehcache.store.offheap.portability.AbstractEhcachePortability.writeSerializables(AbstractEhcachePortability.java:104)
at net.sf.ehcache.store.offheap.portability.AbstractEhcachePortability.writeObjects(AbstractEhcachePortability.java:64)
at net.sf.ehcache.store.offheap.portability.EhcacheKeyPortability.encode(EhcacheKeyPortability.java:39)
... 112 more
Spring configuration file : hibernateSession configuration:
<import resource="hibernateRegistry.xml"/>
<!--Master Hibernate Session Configuration for VOs -->
<bean id="hibernateVOInterceptor" class="com.idi.framework.server.hibernate.HibernateVOInterceptor"/>
<bean id="hibernateSessionFactoryBean" class="com.idi.framework.server.hibernate.HibernateResourcesFactoryBean">
<property name="mappingResources" ref="hbmList"/>
</bean>
<bean id="VOSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
lazy-init="true">
<property name="entityInterceptor" ref="hibernateVOInterceptor"/>
<property name="mappingResources" ref="hibernateSessionFactoryBean"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">com.idi.framework.server.hibernate.IDISybaseDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.connection.provider_class">
com.idi.framework.server.hibernate.IDIConnectionProvider
</prop>
<prop key="current_session_context_class">thread</prop>
<!--<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>-->
<!--http://ehcache.org/documentation/hibernate-upgrade.html-->
<!--http://ehcache.org/documentation/hibernate.html-->
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</prop>
<prop key="hibernate.mapping.precedence">hbm</prop>
<prop key="hibernate.connection.release_mode">on_close</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<!--this is a default but more expressive -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
</props>
</property>
</bean>
CoverRule.hbm.xml
<hibernate-mapping>
<class name="com.idi.policy.premium.common.vo.ifc.CoverRuleMD" abstract="false" table="T_COVER_RULE">
<cache usage="read-only" region="policy.premium"/>
<composite-id>
<key-property name="version" type="integer" column="VERSION"/>
<key-property name="ruleId" type="integer" column="RULE_ID"/>
<key-property name="classSurClass"
type="com.idi.policy.premium.server.model.types.ClassSurClassPairUserType">
<column name="CLASS_CODE" not-null="true"/>
<column name="SUR_CLASS_CODE" not-null="true"/>
</key-property>
<key-property name="identifier" type="com.idi.policy.premium.server.model.types.CoverMDIdentifierUserType">
<column name="CHAPTER_CODE" not-null="true"/>
<column name="COVER_CODE" not-null="true"/>
</key-property>
<key-property name="ruleType">
<column name="RULE_TYPE" not-null="true"/>
<type name="com.idi.general.common.model.usertypes.BasicKeyValueDataTypeUserType">
<param name="keyValueDataTypeClass">com.idi.general.constants.common.datatype.RuleType</param>
</type>
</key-property>
</composite-id>
<many-to-one name="rule" class="com.idi.rulable.engine.common.vo.ifc.RuleMD" lazy="false"
insert="false" update="false" fetch="join">
<column name="RULE_ID"/>
</many-to-one>
</class>
</hibernate-mapping>