tracker issue : CF-4204016

select a category, or use search below
(searches all categories and all time range)
Title:

ClassCastException in Ehcache / Hibernate

| View in Tracker

Status/Resolution/Reason: Open//

Reporter/Name(from Bugbase): A. B. / ()

Created: 02/11/2019

Components: Caching, Distributed Caching

Versions: 13.0

Failure Type: Others

Found In Build/Fixed In Build: 2018.0.01.311402 /

Priority/Frequency: Normal /

Locale/System: / Win 2016

Vote Count: 0

Problem Description: 
We have 2 ColdFusion 2018 instances, one called StudiemeterStaging2018, the other StudiereaderStaging2018. On 2 January 2019 ColdFusion wrote the following error-messages to coldfusion-out.log and hibernatesql.log of the instance StudiemeterStaging2018 (the datasource name is dsn_SM7):

01/02 17:25:54 [_ORM_StudiemeterStaging2018_dsn_SM7] ERROR Error locating Hibernate Session Factory
java.lang.ClassCastException: java.base/java.util.HashMap cannot be cast to java.base/java.util.Properties
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.locateSessionFactory(ProviderMBeanRegistrationHelper.java:142)
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.run(ProviderMBeanRegistrationHelper.java:101)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)

ColdFusion wrote between three and four error messages every minute from 17:25 to 23:43, when it stopped suddenly. Since then no such error messages have been written in StudiemeterStaging2018.

However, yesterday (February 10, 2019) at 11:40:01, ColdFusion suddenly started writing a similar error message to coldfusion-out.log and hibernatesql.log of the other instance, StudiereaderStaging2018:

02/10 11:40:01 [_ORM_StudiereaderStaging2018_dsn_SM7] ERROR Error locating Hibernate Session Factory
java.lang.ClassCastException: java.base/java.util.HashMap cannot be cast to java.base/java.util.Properties
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.locateSessionFactory(ProviderMBeanRegistrationHelper.java:142)
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.run(ProviderMBeanRegistrationHelper.java:101)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)

Steps to Reproduce:
We are as yet unable to reproduce the error. Nevertheless, we suspect that it may be caused by an inconsistency in the class ProviderMBeanRegistrationHelper.class within CF_DIR/lib/hibernate-ehcache-5.2.10.Final.jar.

1) We use distributed cache, that is, ehcache-2.10.6.jar together with terracotta-toolkit-runtime-4.3.6.jar.

 
2) ORM settings in our Application.cfc are:
this.ormSettings={
		cfcLocation: [getDirectoryFromPath(getCurrentTemplatePath()) & "nl/deviant/studiemeter/orm"],
		secondaryCacheEnabled: true,
		cacheProvider: "ehcache",
		eventHandling: true,
		logSql: false,
		searchEnabled: true,
		autoIndex: true,
		language: "Dutch"
	};

3) ehcache.xml and ProviderMBeanRegistrationHelper.java attached

Actual Result: 
The error 
02/10 11:40:01 [_ORM_StudiereaderStaging2018_dsn_SM7] ERROR Error locating Hibernate Session Factory
java.lang.ClassCastException: java.base/java.util.HashMap cannot be cast to java.base/java.util.Properties
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.locateSessionFactory(ProviderMBeanRegistrationHelper.java:142)
	at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.run(ProviderMBeanRegistrationHelper.java:101)
	at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
	at java.base/java.util.TimerThread.run(Timer.java:506)

Expected Result:
1) No such error
2) Correction for the following line of code in ProviderMBeanRegistrationHelper.java:

 // Around line 118
Properties props = (Properties)propertiesField.get(sessionFactory);

Apparently, it fails sometimes because propertiesField.get(sessionFactory) is a Map that cannot be cast to Properties.

Any Workarounds:
None known.

Attachments:

Comments:

A better alternative to the line of code is perhaps: Properties props = new Properties(); props.putAll(propertiesField.get(sessionFactory));
Comment by A. B.
30227 | February 12, 2019 08:41:06 AM GMT