-->
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: Transaction managment in Weblogic
PostPosted: Wed Mar 17, 2004 10:58 am 
Newbie

Joined: Fri Feb 13, 2004 7:59 am
Posts: 8
Location: Gavle, Sweden
Hi,
I have a problem with managing transaction from a stateless EJB in weblogic. I have a weblogic startup class where i bind a sessionfactory to the JNDI-tree. The configuration is as follows:
Configuration cfg = new Configuration()
.addClass(IMArende.class)
.addClass(...)
.addClass(...)
.addClass(...)
.addClass(Varning.class);

cfg.setProperty("hibernate.dialect",
"net.sf.hibernate.dialect.Oracle9Dialect");

cfg.setProperty("hibernate.transaction.factory_class",
"net.sf.hibernate.transaction.JTATransactionFactory");

cfg.setProperty("hibernate.transaction.manager_lookup_class",
"net.sf.hibernate.transaction.WeblogicTransactionManagerLo okup");

SessionFactory factory = cfg.buildSessionFactory();

From my session bean, I fetch a session from a class where I keep the session in a ThreadLocal. The connection for the session is obtained from the connection pool in weblogic:

public class HibernateUtil {

private static final SessionFactory sessionFactory;
private static ServiceLocator locator;


static {
try{
locator = ServiceLocator.getInstance();
sessionFactory = (SessionFactory) locator.getObject("hibernate");
}
}
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
System.out.println("Trying to open session in hibernateutil");

try {
Connection connection = locator.getDataSource ("ihanDS").getConnection();
s = sessionFactory.openSession(connection);
}
catch (NamingException ex) {
ex.printStackTrace();
throw new RuntimeException("Exception trying to find ihanDS: " + ex.getMessage(), ex);
}
catch (SQLException ex) {
ex.printStackTrace();
throw new RuntimeException("Exception trying to obtain connection: " + ex.getMessage(), ex);
}
System.out.println("Succesfully opened session in hibernateutil");
session.set(s);
}
return s;
}

}
My problem is that inside the CMP bean I dont want to use Hibernates Transaction API. Instead I want to use Weblogics CMT, but doing this no data is committed to the DB (which is an Oracle 9.2.1 by the way) and no exception is raised either.
My code in the session bean looks like this:

session = HibernateUtil.currentSession();
session.beginTransaction();
//tx = session.beginTransaction();


IMArende imarende = new IMArende(imaVO);
session.save(imarende);
//tx.commit();

If I uncomment the lines with tx (tx is a Hibernate transaction), the data will be commited to the DB.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 17, 2004 11:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
don't crosspost

_________________
Emmanuel


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.