-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: InitialContext did not implement EventContext
PostPosted: Thu Oct 11, 2007 10:45 am 
Newbie

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 11, 2007 4:11 pm 
Newbie

Joined: Thu Oct 11, 2007 10:41 am
Posts: 4
I test the code:


//This statement is OK.
Session session=HibernateUtil.getSessionFactory().getCurrentSession();

//I get "save is not valid without active transaction" error.
session.save(extranetUserH);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.