Solved

Return value from a Stateless Session Bean

Posted on 2003-11-20
8
714 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
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.…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

9 Experts available now in Live!

Get 1:1 Help Now