Joined: Thu Oct 11, 2007 10:41 am Posts: 4
|
use hibernate3.2, oracle9.2 and websphere 5.1. After I try to configure jndi for the sessionfactory I get the error:
[10/11/07 10:07:33:212 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryImpl building session factory
[10/11/07 10:07:33:961 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryObjectFactory Factory name: java:comp/HibernateSessionFactory
[10/11/07 10:07:33:961 EDT] 75667566 NamingHelper I org.hibernate.util.NamingHelper JNDI InitialContext properties:{}
[10/11/07 10:07:33:961 EDT] 75667566 SessionFactor I org.hibernate.impl.SessionFactoryObjectFactory Bound factory to JNDI name: java:comp/HibernateSessionFactory
[10/11/07 10:07:33:961 EDT] 75667566 SessionFactor W org.hibernate.impl.SessionFactoryObjectFactory InitialContext did not implement EventContext[10/11/07 10:08:31:814 EDT] 75667566 SystemOut O !!!!!Error from HibernateUserDAO.setUserBean :save is not valid without active transaction
The followings are related files:
*hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="hibernate.session_factory_name">
java:comp/HibernateSessionFactory
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>
<property name="hibernate.connection.datasource">
jdbc/NA_DEV1
</property>
* HibernateUtil.java:
public static SessionFactory getSessionFactory() {
String sfName = configuration.getProperty(Environment.SESSION_FACTORY_NAME);
if ( sfName != null) {
//log.debug("Looking up SessionFactory in JNDI");
try {
return (SessionFactory) new InitialContext().lookup(sfName);
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
} else if (sessionFactory == null) {
rebuildSessionFactory();
}
return sessionFactory;
}
...
*My code
public static void setUserBean(ExtranetUserH extranetUserH
) throws Exception {
UserTransaction tx = null;
try {
tx = (UserTransaction) new InitialContext()
.lookup("java:comp/UserTransaction");
tx.begin();
//get save is not valid without active transaction at below statement
HibernateUtil.getSessionFactory().getCurrentSession().save(extranetUserH);
tx.commit();
} catch (Exception e) {
....
The code works without using jndi for sessionfactory. Thanks in advance.
George
|
|