Solved

Return value from a Stateless Session Bean

Posted on 2003-11-20
8
716 Views
Last Modified: 2013-12-01
Hello Expert,

We have a Stateless Session Bean deployed in a oc4j server. A function in the bean returns a HashTable. Using traces we found that just before returning from the function, the hashtable has 14 key entries. Each entry contains a vector of size 130. But when the hashtable is received in the client, it is null. And this behavior is inconsistent, i.e., we get the correct hashtable sometimes.

Any idea why this could happen?

Thanks.
0
Comment
Question by:R_Anuradha
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:FBIAGENT
ID: 9800603
Please cut and paste the implementation of the bean and of the bean caller?
0
 

Author Comment

by:R_Anuradha
ID: 9823790
The bean implementation is:

    public Hashtable executeSelectQuery(String tableName[], String columnName[],
                                     String conditionString)
{
            Connection d_con = null;
            Statement d_stmt = null;
            String   d_strSQL =  null;
            ResultSet rs=null;
        try
        {
            Context  initialContext = new InitialContext();
            DataSource dataSource   = null;                // datasource object
            dataSource = (DataSource)initialContext.lookup("jdbc/OracleDS");
            d_con =  dataSource.getConnection();
            d_stmt = d_con.createStatement();
        }
        catch(Exception e)
        {
            TraceMessage.printMessageWithDateTime("SelectQuerySLSBean :" +
                            "Error in getting the conection" + e);
        }

        String strTableName = "";

        // Add "," in between the column names for the SQL query.
        if(tableName.length >= 2)
        {
            for(int i = 0; i< (tableName.length - 1); i++)
            {
                    strTableName = strTableName + tableName[i] + ",";
            }
        }
        strTableName = strTableName + tableName[tableName.length - 1];

        String strColumnName = "";

        // Add "," in between the column names for the SQL query.
        if(columnName.length >= 2)
        {
            for(int i = 0; i< (columnName.length - 1); i++)
            {
                    strColumnName = strColumnName + columnName[i] + ",";
            }
        }
        strColumnName = strColumnName + columnName[columnName.length - 1];

        // If the condition string is null or empty don't add the where
        // condition.
        d_strSQL =  "select unique " + strColumnName + " from "+ strTableName;
        if ( conditionString != null && conditionString.trim().length() > 0 )
        {
            d_strSQL =  d_strSQL + " where " + conditionString;
        }

        try
        {
            rs = d_stmt.executeQuery(d_strSQL);
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }

        Hashtable resultTable = new Hashtable();
        int iCnt = 0; // For record count
        try
        {
            Vector[] columnVtr = new Vector[columnName.length];
            for(int i = 0; i< columnName.length; i++)
            {
                  columnVtr[i] = new Vector();
            }

            while(rs.next())
            {      
                iCnt++;
                for(int i = 0; i< columnName.length; i++)
                {
                    columnVtr[i].addElement(rs.getObject
                            (columnName[i]));
                }

            }
            TraceMessage.printMessageWithDateTime("Record count: "+iCnt);
              for(int i = 0; i< columnName.length; i++)
            {
                resultTable.put(columnName[i], columnVtr[i]);
            }
        }
        catch(Exception e)
        {
                e.printStackTrace();
        }

        finally
        {
            // Always clean up properly!
            try
            {
      if (rs != null)
      {
            rs.close();
      }
                if (d_stmt != null)
                {
                        d_stmt.close();
                }
                if (d_con != null)
                {
                        d_con.close();
                }
            }
            catch (SQLException e)
            {
                e.printStackTrace();
            }
        }
      
       if (resultTable!= null)
           TraceMessage.printMessageWithDateTime("Actual Hashtable size just before returning: "+resultTable.size());
       else
           TraceMessage.printMessageWithDateTime("result table is null just before returning");      
        return resultTable;
    }

******************
Bean caller:

public static Hashtable executeSelectQuery(String []tableNames,
            String [] columnNames, String whereCondition)
    {
        Hashtable result = null;

        try
        {
            // Call the Remote method
            result = selectQuerySLS.executeSelectQuery(tableNames,
                columnNames, whereCondition);
            if (result != null)
                   System.out.println("Valid hashtable returned");
            else
                   System.out.println("hashtable is null");
        }
        catch(Throwable e)
        {
            e.printStackTrace();
        }

        return result;
    }

***********

The bean implementation gives the trace: "Actual Hashtable size just before returning: 14"

The bean caller gives the trace: "hashtable is null"

If you can find any casue for this strange behaviour, kindly let us know.
Thanks.
0
 
LVL 9

Expert Comment

by:vzilka
ID: 9823951
What OC4J version are you using? I ran it using OC4J 10g and it works fine.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:R_Anuradha
ID: 9829567
We are using Oracle9i - version 9.0.1. We are getting this problem frequently in one Server and it does work fine sometimes in the same Server. And in another Server we get this problem occasionally and other times it works fine. So, its an inconsistent behaviour in the Server.
0
 
LVL 9

Expert Comment

by:vzilka
ID: 9829826
I guess you mean OC4J 1.0.2.2.1.
This is an old version.

Can you try to localize the problem? What happens if the Hashtable contains just one item? Does it work then?

I think this is bug in the RMI serialization mechanism. It was probably fixed in a later version. Can you upgrade your Oracle9iAS version?
0
 

Author Comment

by:R_Anuradha
ID: 10059481
We have upgraded the Server with Oracle 9iAS 9.0.3. We redeployed all the Beans. The problem with RMI Serialisation does not seem to occur. However, we have a problem at the next step, where another function in the bean is called.

We get the following error:
<snip>
com.evermind.server.rmi.OrionRemoteException: Error in setSessionContext(): getU
serTransaction() cannot be invoked from setSessionContext()
        at com.evermind.server.ejb.StatelessSessionEJBHome.getContextInstance(St
atelessSessionEJBHome.java:247)
        at ModifyTestPlanSLS_StatelessSessionBeanWrapper0.addTest(ModifyTestPlan
SLS_StatelessSessionBeanWrapper0.java:193)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:119)
        at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
utor.java:803)
        at java.lang.Thread.run(Thread.java:479)
at connection to 192.168.42.125/192.168.42.125 as admin
        at com.evermind.server.rmi.RMIConnection.EXCEPTION_ORIGINATES_FROM_THE_R
EMOTE_SERVER(RMIConnection.java:1530)
        at com.evermind.server.rmi.RMIConnection.invokeMethod(RMIConnection.java
:1453)
        at com.evermind.server.rmi.RemoteInvocationHandler.invoke(RemoteInvocati
onHandler.java:53)
        at com.evermind.server.rmi.RecoverableRemoteInvocationHandler.invoke(Rec
overableRemoteInvocationHandler.java:22)
        at com.evermind.server.ejb.StatelessSessionRemoteInvocationHandler.invok
e(StatelessSessionRemoteInvocationHandler.java:50)
        at __Proxy11.addTest(Unknown Source)
        at com.sciatl.svt.ui.testplanning.TPEJBCallWrapper.addTest(TPEJBCallWrap
per.java:311)
        at com.sciatl.svt.ui.testplanning.ModifyTestPlanContents.saveTestPlan(Mo
difyTestPlanContents.java:1579)
        at com.sciatl.svt.ui.testplanning.ModifyTestPlanContents.actionPerformed
(ModifyTestPlanContents.java:1882)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknow
n Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

        Nested exception is:
java.lang.IllegalStateException: getUserTransaction() cannot be invoked from set
SessionContext()
        at com.evermind.server.ejb.AbstractEJBContext.getUserTransaction(Abstrac
tEJBContext.java:184)
        at com.sciatl.svt.ejb.testplanning.impl.ModifyTestPlanSLSBean.setSession
Context(ModifyTestPlanSLSBean.java:90)
        at com.evermind.server.ejb.StatelessSessionEJBHome.getContextInstance(St
atelessSessionEJBHome.java:240)
        at ModifyTestPlanSLS_StatelessSessionBeanWrapper0.addTest(ModifyTestPlan
SLS_StatelessSessionBeanWrapper0.java:193)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:119)
        at com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExec
utor.java:803)
        at java.lang.Thread.run(Thread.java:479)
at connection to 192.168.42.125/192.168.42.125
        at com.evermind.server.rmi.OrionRemoteException.receive(OrionRemoteExcep
tion.java:130)
        at com.evermind.server.rmi.RMIConnection.handleMethodInvocationResponse(
RMIConnection.java:1644)
        at com.evermind.server.rmi.RMIConnection.run(RMIConnection.java:496)
        at java.lang.Thread.run(Unknown Source)
<snip>

In the above listing, the error says that '__Proxy11.addTest(Unknown Source)' . However, the bean 'ModifyTestPlan' does contain the function addTest().

Could this problem be due to the upgradation?

Thanks.
0
 
LVL 9

Accepted Solution

by:
vzilka earned 125 total points
ID: 10059808
It seems you have an error in your code. It is illegal to call getUserTransaction() method from the setSessionContext() method of a stateless session bean. The reason is that the setSessionContext is not neccessarily called by a user, and so there might not be a UserTransaction, or that UserTransaction might be different when another EJB method is called.

Remove that method call. I think this is why your method is not recognized.
0
 

Author Comment

by:R_Anuradha
ID: 10060312
Thanks a lot. We removed the getUserTransaction method call and the problem got solved..
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMS9 install on Yosemite, can't get Deployment Wizard to run 7 252
activemq cluster 1 237
Problem to refer to codes 10 121
Basics of Drool Rule Engine with few samples 2 69
Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question