"Exception data: java.lang.IllegalStateException: Illegal operation: tried to commit connection in global transaction"
This is the error message when I try to run my EJB session bean in WSAD5.0.
Here is the hibernate.cfg.xml content:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Data Source -->
<property name="connection.datasource">jdbc/Bankdata</property>
<!-- Database Settings -->
<!--property name="default_schema">SCHIMA_NAME</property-->
<property name="dialect">net.sf.hibernate.dialect.DB2Dialect</property>
<property name="show_sql">true</property>
<!-- JDBC Settings -->
<property name="jdbc.use_streams_for_binary">true</property>
<property name="max_fetch_depth">1</property>
<!-- Cache settings -->
<property name="cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
<!-- Transaction API -->
<property name="transaction.manager_lookup_class">
net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<!-- Mapping files -->
<mapping resource="Blog.hbm.xml"/>
<mapping resource="BlogItem.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Here is the HibernateTestBean (EJB session bean) content:
Code:
package com.hibernate.blog.ejb;
import net.sf.hibernate.HibernateException;
//import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
//import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
import com.hibernate.blog.Blog;
import com.hibernate.blog.BlogItem;
import java.util.ArrayList;
import java.util.List;
/**
* Bean implementation class for Enterprise Bean: HibernateTest
*/
public class HibernateTestBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;
private SessionFactory sessions = null;
/**
* doService
*/
public void doService() throws Exception {
cleanDatabase();
Blog blog = new Blog();
blog.setName("Nenad Prnic");
blog.setItems( new ArrayList() );
Session session = sessions.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(blog);
tx.commit();
}
catch (HibernateException he) {
if (tx!=null) tx.rollback();
throw he;
}
finally {
session.close();
}
}
/**
* cleanDatabase()
*/
private static void cleanDatabase() throws Exception
{
java.sql.Connection con;
try
{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
con =
java.sql.DriverManager.getConnection(
"jdbc:db2:Bankdata",
"prnicn",
"pentagon");
}
catch (Exception e)
{
throw new RuntimeException("couldn't get connection");
}
java.sql.Statement stmt = con.createStatement();
stmt.executeUpdate("delete from Blogs");
stmt.executeUpdate("delete from Blog_Items");
stmt.close();
}
/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
try {
sessions = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
System.out.print(" Exception creating SessionFactory object: " + e.getMessage());
}
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
}
The complete error message is as follows:
Code:
[3/8/04 13:32:23:383 EST] a2985ab Environment I net.sf.hibernate.cfg.Environment Hibernate 2.1.1
[3/8/04 13:32:23:398 EST] a2985ab Environment I net.sf.hibernate.cfg.Environment hibernate.properties not found
[3/8/04 13:32:23:398 EST] a2985ab Environment I net.sf.hibernate.cfg.Environment using CGLIB reflection optimizer
[3/8/04 13:32:23:398 EST] a2985ab Environment I net.sf.hibernate.cfg.Environment JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
[3/8/04 13:32:23:398 EST] a2985ab Environment I net.sf.hibernate.cfg.Environment using workaround for JVM bug in java.sql.Timestamp
[3/8/04 13:32:23:414 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration configuring from resource: /hibernate.cfg.xml
[3/8/04 13:32:23:414 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration Configuration resource: /hibernate.cfg.xml
[3/8/04 13:32:23:664 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration Mapping resource: Blog.hbm.xml
[3/8/04 13:32:23:992 EST] a2985ab Binder I net.sf.hibernate.cfg.Binder Mapping class: com.hibernate.blog.Blog -> BLOGS
[3/8/04 13:32:24:227 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration Mapping resource: BlogItem.hbm.xml
[3/8/04 13:32:24:289 EST] a2985ab Binder I net.sf.hibernate.cfg.Binder Mapping class: com.hibernate.blog.BlogItem -> BLOG_ITEMS
[3/8/04 13:32:24:305 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration Configured SessionFactory: null
[3/8/04 13:32:24:305 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration processing one-to-many association mappings
[3/8/04 13:32:24:305 EST] a2985ab Binder I net.sf.hibernate.cfg.Binder Mapping collection: com.hibernate.blog.Blog.items -> BLOG_ITEMS
[3/8/04 13:32:24:305 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration processing one-to-one association property references
[3/8/04 13:32:24:305 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration processing foreign key constraints
[3/8/04 13:32:24:352 EST] a2985ab Dialect I net.sf.hibernate.dialect.Dialect Using dialect: net.sf.hibernate.dialect.DB2Dialect
[3/8/04 13:32:24:367 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Maximim outer join fetch depth: 1
[3/8/04 13:32:24:367 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use outer join fetching: true
[3/8/04 13:32:24:383 EST] a2985ab NamingHelper I net.sf.hibernate.util.NamingHelper JNDI InitialContext properties:{}
[3/8/04 13:32:24:539 EST] a2985ab DatasourceCon I net.sf.hibernate.connection.DatasourceConnectionProvider Using datasource: jdbc/Bankdata
[3/8/04 13:32:24:555 EST] a2985ab TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
[3/8/04 13:32:24:555 EST] a2985ab TransactionMa I net.sf.hibernate.transaction.TransactionManagerLookupFactory instantiated TransactionManagerLookup
[3/8/04 13:32:25:398 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Use scrollable result sets: true
[3/8/04 13:32:25:398 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory echoing all SQL to stdout
[3/8/04 13:32:25:398 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory Query language substitutions: {}
[3/8/04 13:32:25:398 EST] a2985ab SettingsFacto I net.sf.hibernate.cfg.SettingsFactory cache provider: net.sf.hibernate.cache.HashtableCacheProvider
[3/8/04 13:32:25:414 EST] a2985ab Configuration I net.sf.hibernate.cfg.Configuration instantiating and configuring caches
[3/8/04 13:32:25:758 EST] a2985ab SessionFactor I net.sf.hibernate.impl.SessionFactoryImpl building session factory
[3/8/04 13:32:27:164 EST] a2985ab SessionFactor I net.sf.hibernate.impl.SessionFactoryObjectFactory no JNDI name configured
[3/8/04 13:32:27:164 EST] a2985ab WebSphereTran I net.sf.hibernate.transaction.WebSphereTransactionManagerLookup WebSphere 5
[3/8/04 13:32:27:164 EST] a2985ab SystemOut O HibernateTestBean.doService() called successfully!
[3/8/04 13:32:27:164 EST] a2985ab SystemOut O HibernateTestBean.doService() Start cleaning Database object!
[3/8/04 13:32:27:195 EST] a2985ab SystemOut O HibernateTestBean.doService() Database cleaned successfully!
[3/8/04 13:32:27:289 EST] a2985ab SystemOut O Hibernate: values nextval for blog_id_seq
[3/8/04 13:32:27:461 EST] a2985ab SystemOut O Hibernate: insert into BLOGS (NAME, BLOG_ID) values (?, ?)
[3/8/04 13:32:27:477 EST] a2985ab ExceptionUtil E CNTR0020E: Non-application exception occurred while processing method "doService" on bean "BeanId(ewwcms_hibernateEAR#hibernate_ejb.jar#HibernateTest, null)". Exception data: java.lang.IllegalStateException: Illegal operation: tried to commit connection in global tran
at com.ibm.ejs.cm.pool.ConnectO.commit(ConnectO.java:2405)
at com.ibm.ejs.cm.proxy.ConnectionProxy.commit(ConnectionProxy.java:643)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:63)
at com.hibernate.blog.ejb.HibernateTestBean.doService(HibernateTestBean.java:50)
at com.hibernate.blog.ejb.EJSRemoteStatelessHibernateTest_78f332c6.doService(EJSRemoteStatelessHibernateTest_78f332c6.java:34)
at com.hibernate.blog.ejb._HibernateTest_Stub.doService(_HibernateTest_Stub.java:257)
at com.cot.ewwcms.web.struts.LogonAction.execute(LogonAction.java:83)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)
[3/8/04 13:32:27:695 EST] a2985ab SystemErr R org.omg.CORBA.portable.UnknownException: minor code: 0 completed: Maybe
Basically the line that causes the error is within the doService() method: tx.commit();
Can someone help and explain to me what I am doing wrong?