Hi,
I use JBoss 2.4.4, Stateless Session Beans with CMP which extends ServiceProvider.
The code looks like this:
...
initialize();
naidSQL = (String) EJBUtilities.lookupEnv("sqlUniqueNumber/wlttosap",iCtx);
try {
statement = DBClient.getConnection(iCtx).prepareStatement(naidSQL);
resultSet = statement.executeQuery();
if (resultSet.next()){
naid = resultSet.getLong(1);
} else {
naid = -1;
}
} catch (SQLException e) {
throw new SQLErrorException(naidSQL,e);
}
protected void initialize() throws RemoteException{
//Close the present databaseconnection
try {
DBClient.close();
} catch (Exception e) {
e.printStackTrace();
}
super.initialize();
}
ServiceProvider:
protected void initialize() throws RemoteException {
try {
iCtx = EJBUtilities.getInitialContext();
} catch (Exception e) {
throw new RemoteException("Could not lookup service provider name in the enviroment!");
}
}
DBClient:
public static final void close() throws SystemException, BusinessException {
try {
if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (SQLException e) {
throw new SQLErrorException(e);
}
}
The problem is that I can execute this only one time, by the second the connection.close() throw the following exception:
[ERROR,Default] java.lang.RuntimeException: Unable to deregister with TransactionManager: java.lang.IllegalArgumentException: xaRes not enlisted
That’s why I have always the connection to the wrong database.
The same code works on other EJB servers. Whats wrong?
Thanks for your help!
Kerstin