1

単一の Tomcat ノードで Hibernate を使用していますが、クラスターで実行しようとすると、次のエラーが発生します。

SEVERE: IOException while loading persisted sessions: java.io.InvalidObjectException: Could not find a SessionFactory [uuid=158c1e24-039b-4406-9a9b-cebb836100d1,name=null]
java.io.InvalidObjectException: Could not find a SessionFactory [uuid=158c1e24-039b-4406-9a9b-cebb836100d1,name=null]
at org.hibernate.internal.SessionFactoryImpl.locateSessionFactoryOnDeserialization(SessionFactoryImpl.java:1767)
at org.hibernate.internal.SessionFactoryImpl.readResolve(SessionFactoryImpl.java:1747)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1091)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1786)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1970)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1894)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1970)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1894)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1970)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1894)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1970)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1894)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1485)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:987)
at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:394)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:321)
at org.apache.catalina.session.StandardManager.start(StandardManager.java:648)
at org.apache.catalina.core.ContainerBase.setManager(ContainerBase.java:446)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
at org.mobicents.servlet.sip.startup.SipHostConfig.deployWAR(SipHostConfig.java:134)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
at org.mobicents.servlet.sip.startup.SipHostConfig.deployWARs(SipHostConfig.java:205)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
at org.mobicents.servlet.sip.startup.SipHostConfig.deployApps(SipHostConfig.java:55)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.mobicents.servlet.sip.startup.SipStandardEngine.start(SipStandardEngine.java:98)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.mobicents.servlet.sip.startup.SipStandardService.start(SipStandardService.java:290)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

RecordingHibernateUtil と呼ばれる私の HibernateUtil クラスは次のとおりです。

public class RecordingHibernateUtil {

public static final String CONFIG_FILENAME = "hibernate-recording.cfg.xml";
public static final String RECORDING_DB_URL = "recording.db.url";
public static final String RECORDING_DB_DRIVER = "recording.db.driver";
public static final String RECORDING_DB_USERNAME = "recording.db.username";
public static final String RECORDING_DB_PASSWORD = "recording.db.password";

private static SessionFactory sessionFactory = null;

public static void buildSessionFactory() {
    if (sessionFactory != null) {
        //Already configured
        return;
    }
    Properties props;
    try {
        props = DBConfiguration.getInstance().getProperties();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Configuration config = new Configuration().configure(CONFIG_FILENAME);
    config.setProperty("hibernate.connection.url", 
            props.getProperty(RECORDING_DB_URL, 
                    props.getProperty(DBConfiguration.DB_URL)));
    config.setProperty("hibernate.connection.driver_class", 
            props.getProperty(RECORDING_DB_DRIVER, 
                    props.getProperty(DBConfiguration.DB_DRIVER)));
    config.setProperty("hibernate.connection.username", 
            props.getProperty(RECORDING_DB_USERNAME, 
                    props.getProperty(DBConfiguration.DB_USERNAME)));
    config.setProperty("hibernate.connection.password", 
            props.getProperty(RECORDING_DB_PASSWORD, 
                    props.getProperty(DBConfiguration.DB_PASSWORD)));
    try {
        sessionFactory = config.buildSessionFactory();
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

public static void shutdown() {
    // Close caches and connection pools
    getSessionFactory().close();
}
}

インターネット検索から、Hibernate SessionFactory をシリアライズしようとしているように聞こえました。これを防ぐために、JNDI ルックアップを使用して SessionFactory を取得することが提案されました。これは正しいです?とにかくSessionFactoryをシリアライズしようとしている理由がわかりません。(現在、SessionFactory を HibernateUtil クラスの静的変数に格納しています... この方法を維持したいです。)

JNDI を使用することは本当に必要ですか? どうすればこれを行うことができますか?Tomcat と JBoss (できれば) の両方で機能するソリューション、またはそれぞれに個別のソリューションが必要です。

4

1 に答える 1