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.
|