Solved

Return value from a Stateless Session Bean

Posted on 2003-11-20
8
715 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now