I am trying to setup EHCache in distributed environment with Terracotta. Here I am able to connect Application server and Terracotta server and in terracotta Developer Console I am able to see replicated objects.

But in application server continiously following exception message is appearing, though rest of the application is running properly:

Hi All, if any body can guide why this exception message appears and how we can resolve it. Also it would be helpful for me have any comprehensive tutorial for setting up terracotta for hibernate application.

Here [CacheByAmitNode8081] is the name of cache node I have defined in application server.

[DEBUG][04/05/12 12:49:07.973][CacheByAmitNode8081] Running mbean initializer task for ehcache hibernate...
[DEBUG][04/05/12 12:49:07.995][CacheByAmitNode8081] Successfully registered bean
[ERROR][04/05/12 12:49:08.000][CacheByAmitNode8081] Error locating Hibernate Session Factory
java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.get(UnsafeQualifiedObjectFieldAccessorImpl.java:20)
at java.lang.reflect.Field.get(Field.java:358)
at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.locateSessionFactory(ProviderMBeanRegistrationHelper.java:152)
at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.run(ProviderMBeanRegistrationHelper.java:117)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
[DEBUG][04/05/12 12:49:08.001][CacheByAmitNode8081] SessionFactory is probably still being initialized... waiting for it to complete before enabling hibernate statistics monitoring via JMX
[DEBUG][04/05/12 12:49:08.001][CacheByAmitNode8081] Running mbean initializer task for ehcache hibernate...
[ERROR][04/05/12 12:49:08.001][CacheByAmitNode8081] Error locating Hibernate Session Factory
java.lang.NullPointerException
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:36)
at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.get(UnsafeQualifiedObjectFieldAccessorImpl.java:20)
at java.lang.reflect.Field.get(Field.java:358)
at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.locateSessionFactory(ProviderMBeanRegistrationHelper.java:152)
at org.hibernate.cache.ehcache.management.impl.ProviderMBeanRegistrationHelper$RegisterMBeansTask.run(ProviderMBeanRegistrationHelper.java:117)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)*
有帮助吗?

解决方案

When you using Terracotta, you need to add specific terracotta jars on your classpath that will replace ehcache implementation. In your exception stack I don't see any terracotta classes output...

In my maven dependencies I have:

<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache-core-ee</artifactId>
  <version>2.5.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>net.sf.ehcache</groupId>
  <artifactId>ehcache-terracotta-ee</artifactId>
  <version>2.5.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.terracotta</groupId>
  <artifactId>terracotta-toolkit-1.5-runtime-ee</artifactId>
  <version>4.2.0</version>
  <scope>compile</scope>
</dependency>

You can also check Terracotta tutorial on how to plug to Hibernate: http://terracotta.org/documentation/enterprise-ehcache/get-started-hibernate

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top