Glassfishアプリケーションサーバーに永続性プロバイダーとしてHibernateを実装することで遊んでいます。JNDIデータソース、接続プールなどをすでに構成しました。Hibernateの構成は次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">jdbc/myDatasource</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.session_factory_name">hibernateSessionFactory</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<property name="hibernate.current_session_context_class">thread</property>
<mapping class="org.me.jsf.entities.Node" />
</session-factory>
</hibernate-configuration>
このようにSessionFactoryを使用しようとすると、次のようになります。
try {
sessionFactory = (SessionFactory) new InitialContext()
.lookup("hibernateSessionFactory");
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
ログによると、「'hibernateSessionFactory'のルックアップに失敗しました」が原因で例外「ExceptionInInitializerError」が発生します。しかし、私がこのコードを使用するとき:
try {
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure();
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
...すべてうまくいきます。
ここで何が間違っていたのですか?私はfaces-config.xmlの関連するクラスのマネージドBeanhibernateSessionFactoryのエントリを作成しようとしましたが、それでも運がありません...