Dzięki za szybką odpowiedź. Samo context_session nie wystarcza, dostaję taki błąd:
org.hibernate.HibernateException: No TransactionManagerLookup specified
Sprawdziłem w logach serwera, co się dzieje:
SEVERE No TransactionManagerLookup specified javax.faces.el.EvaluationException: org.hibernate.HibernateException: No TransactionManagerLookup specified at com.sun.faces.application.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91) at
--- ciach! ---
org.hibernate.HibernateException: No TransactionManagerLookup specified at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:54) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544) at model.dao.UserDao.getUser(UserDao.java:28) at model.service.impl.UserService.login(UserService.java:37) at model.bean.pageBean.login.LoginBean.loginAction(LoginBean.java:45) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
WARNING JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()
Wywala się przy próbie pobrania sesji (session.getCurrentSession()) od Transaction Managera. Wydaje mi się, że trzeba go jakoś podpiąć dzięki JNDI, ale może da się jakoś inaczej. Plik konfiguracyjny wygląda następująco:
<?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.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/xxx</property>
<property name="hibernate.connection.username">xxx</property>
<property name="hibernate.connection.password">xxx</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">jta</property>
<!--<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">???</property>-->
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<mapping resource="model/business/Workspace.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mam nadzieję, że udzieliłem wystarczających informacji.
edit Dorzucę jeszcze w jaki sposób pobieram Session:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
public HibernateUtil() {};
private static SessionFactory buildSessionFactory() {
try {
return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Przykładowe użycie:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();