使用EHCache在Terracotta配置中查找Hibernate会话工厂时出错

时间:2012-05-09 05:32:02

标签: hibernate ehcache

任何人都可以帮助我为什么在应用服务器上会出现以下错误消息。我正在尝试用Terracotta设置EHCache。请提出任何线索,以便显示此消息的原因。

[DEBUG][08/05/12 13:50:19.648][CacheByAmitNode8081] Running mbean initializer task for ehcache hibernate...
[DEBUG][08/05/12 13:50:19.766][CacheByAmitNode8081] Successfully registered bean
[ERROR][08/05/12 13:50:19.805][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][08/05/12 13:50:19.815][CacheByAmitNode8081] SessionFactory is probably still being initialized... waiting for it to complete before enabling hibernate statistics monitoring via JMX

1 个答案:

答案 0 :(得分:1)

今天我遇到了同样的问题。这似乎是由第152行的ProviderMBeanRegistrationHelper类中的错误导致的

Map map = (Map) instancesField.get( null );

在146行和147行中我们有

Class factoryType = SessionFactoryRegistry.class;
Field instancesField = getField( factoryType, "sessionFactoryMap" );

所以我们知道instanceField是一个来自SessionFactoryRegistry类的实例的字段,它碰巧有一个可以从类中静态获取的实例

SessionFactoryRegistry.INSTANCE

总之,我修改了第152行如下

Map map = (Map) instancesField.get( SessionFactoryRegistry.INSTANCE );

编译并替换了hibernate-ehcache jar文件中的类,异常消失了。我将就此提出一个问题。