on 12-12-2014 5:14 AM
HI,
I am Accessing the data source which is configured in SAP NetWeaver AS for a Java Schedulers Application. The job of this scheduler is to insert
the data into a table. Below is the code.
Please note I am using Enterprise Java Beans for the java schedulers Applicaton on Java AS
Getting connection from DataSource:
public class ConnectionUtil
{
public static Connection getConnection() throws NamingException, SQLException
{
Connection connection = null;
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("jdbc/***");
connection = ds.getConnection();
connection.setAutoCommit(false);
return connection;
}
}
Code that simply inserting a Values in table:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "JobDefinition='testInsert'")
})
public class Test extends MDBJobImplementation
{
public void onJob(JobContext ctx) throws Exception
{
try
{
Connection conn = ConnectionUtil.getConnection();
PreparedStatement stmt;
CallableStatement callstmt;
String insertSql = "insert into TEST(F_NAME,L_NAME) values(?,?)";
stmt = conn.prepareStatement(insertSql );
stmt.setString(1, "FirstName");
stmt.setString(2, "LastName");
stmt.executeUpdate();
}finally
{
conn.commit();
conn.close();
}
}
}
I am Getting below Exception for above code:
[EXCEPTION]
java.security.PrivilegedActionException: com.sap.engine.services.dbpool.exceptions.BaseSQLException: Cannot commit JDBC transaction from this connection of "***" DataSource. This resource participates in a JTA transaction.
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:394)
at com.sap.engine.services.scheduler.runtime.mdb.MDBJobDelegateImpl.onMessage(MDBJobDelegateImpl.java:300)
at com.sap.scheduler.runtime.mdb.MDBJobImplementation.onMessage(MDBJobImplementation.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(RequestInvocationContext.java:47)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:166)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:50)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_MessageListenerType.invoke(Interceptors_MessageListenerType.java:86)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:191)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:23)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:25)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:17)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Lock.invoke(Interceptors_Lock.java:21)
at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:138)
at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:172)
at com.sap.engine.services.ejb3.runtime.impl.MDBProxyInvocationHandler.invoke(MDBProxyInvocationHandler.java:142)
at com.sun.proxy.$Proxy1693.onMessage(Unknown Source)
at com.sap.jms.client.session.JMSSession.deliverMessage(JMSSession.java:1075)
at com.sap.jms.client.session.JMSSession.run(JMSSession.java:898)
at com.sap.jms.resourceadapter.RaServerSession.run(RaServerSession.java:139)
at com.sap.engine.services.connector.jca15.work.TaskImpl.run(TaskImpl.java:410)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:122)
at com.sap.engine.core.thread.execution.Executable.run(Executable.java:101)
at com.sap.engine.core.thread.execution.CentralExecutor$SingleThread.run(CentralExecutor.java:328)
Caused by: com.sap.engine.services.dbpool.exceptions.BaseSQLException: Cannot commit JDBC transaction from this connection of "***" DataSource. This resource participates in a JTA transaction.
at com.sap.engine.services.dbpool.cci.ConnectionHandle.commit(ConnectionHandle.java:233)
at com.sap.scheduler.Test.onJob(Test.java:211)
at com.sap.engine.services.scheduler.runtime.mdb.MDBJobDelegateImpl$2.run(MDBJobDelegateImpl.java:266)
Hi Dipak,
As you mentioned that you are using EJB and the fact is that EJB doesn't do trasaction management at connection level. It uses the Java Transaction Services to creat transactions which can use multiple connections.
Pleaes revisite your code.
Thanks,
Hamendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.