Я использую hibernate-core-4.2.21.Final на Websphere 8.5.5.4.
Конфигурация Hibernate выглядит следующим образом:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="mySessionFactory">
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.connection.datasource">MyDS</property>
<property name="hibernate.default_schema">dbo</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.jndi.class">com.ibm.websphere.naming.WsnInitialContextFactory</property>
<property name="hibernate.jndi.url">corbaloc::myapp-prod-fnicn1.my.com:2809,:myapp-prod-FNICN2.my.com:2809,:myapp-prod-fnicn1.my.com:2811,:myapp-prod-FNICN2.my.com:2811,:myapp-prod-fnicn1.my.com:2812,:myapp-prod-FNICN2.my.com:2812</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<mapping resource="gov/mci/efada/entities/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Как настроить Hibernate:
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
.buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Как получить фабрику сессий:
sessionFactory = (SessionFactory) new InitialContext().lookup("mySessionFactory");
Иногда поиск SessionFactory создает:
javax.naming.Reference incompatible with org.hibernate.SessionFactory