[EJB 3.0] - Retrieve the current transaction id in an session bean
by benc
Part of my application's requirements involve me saving the transaction id of some operations. I am using a CMT StatelessSessionBean. I thought that I could get the id via entityManager.getTransaction(), but that yields the following IllegalStateException. Is there another way to get to this information without switching to user managed transactions?
| java.lang.IllegalStateException: Illegal to call this method from injected, managed EntityManager
| at org.jboss.ejb3.entity.TransactionScopedEntityManager.getTransaction(TransactionScopedEntityManager.java:226)
| at com.noverant.service.audit.StatelessAuditService.addEntry(StatelessAuditService.java:69)
| at sun.reflect.GeneratedMethodAccessor183.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:597)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| ...
|
Relevant portions of the class that is generating this error:
| package com.noverant.service.audit;
|
| import ...
|
| @Stateless (name="AuditService")
| public class StatelessAuditService implements AuditService
| {
| protected EntityManager entityManager = null;
| protected SessionContext sessionContext = null;
|
| @PersistenceContext(unitName = "nets-system")
| public void setEntityManager(EntityManager entityManager)
| {
| this.entityManager = entityManager;
| }
|
| @Resource
| public void setSessionContext(SessionContext sessionContext)
| {
| this.sessionContext = sessionContext;
| }
|
| public void addEntry(AuditEntry ae)
| {
| String transactionId = entityManager.getTransaction().toString();
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112726#4112726
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4112726
18 years, 6 months
[Persistence, JBoss/CMP, Hibernate, Database] - org.jboss.resource.adapter.jdbc.WrappedCallableStatement
by cybercollege
I have done a lot of search and also have tried whatever I could fine but the issue could not be resoved. When I run the code I get the following error:
Error in java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.WrappedCallableStatement"
Here is a part of the code:
import oracle.jdbc.OracleCallableStatement;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.pool.OracleDataSource;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.sql.*;
............
........
.....
OracleCallableStatement cstmt = null;
String[] orgNames = null;
int maxTablLen = 250;
int eleMaxLen = 100;
try{
ConnPool conObj = new ConnPool();
con = conObj.getConnection();
cstmt = (OracleCallableStatement) con.prepareCall(" begin"+
"GETS_LMS_RECAP_DEFECTS_PKG.GETS_PL_SQL_TEST(?);"+
" end;");
cstmt.registerIndexTableOutParameter(1,maxTablLen,OracleTypes.VARCHAR,eleMaxLen);
cstmt.execute();
orgNames = (String [])cstmt.getObject(1);
System.out.println("Number of rows= "+orgNames.length);
for (int i=0; i<orgNames.length; i++){
System.out.print(orgNames);
System.out.println();
}
The exception is thrown prior to even executing "cstmt.execute();".
Please advise how to fix this error?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112720#4112720
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4112720
18 years, 6 months