Return value from a Stateless Session Bean

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.
R_AnuradhaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FBIAGENTCommented:
Please cut and paste the implementation of the bean and of the bean caller?
0
R_AnuradhaAuthor Commented:
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
vzilkaCommented:
What OC4J version are you using? I ran it using OC4J 10g and it works fine.
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

R_AnuradhaAuthor Commented:
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
vzilkaCommented:
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
R_AnuradhaAuthor Commented:
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
vzilkaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
R_AnuradhaAuthor Commented:
Thanks a lot. We removed the getUserTransaction method call and the problem got solved..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.