JAAS and stateless bean

i have a very simple stateless bean with a single "hello" method running in WL 8.1 sp3. to test out Weblogic's behavior, i ran 2 seaparate scenarios on 2 separate occasions. in the first one, i secured all bean methods. in the 2nd one, i secured only the home's "create" mthod, while explicitely denoting all remote methods as "unchecked". next, i wrote a standalone client class where the aforemention bean's EJBHome.create() is called from within a PrivilegedAction-inherited class, while hello() method is called straight up without the use of PrivilegedAction. moreover, the hello() method also prints out the SessionContext.getCallerPrincipal().getName(). finally, an UNsecured servlet utilizing that class was deployed in Tomcat5 and another instance of Weblogic. this is where is gets interesting. when executing the standalone class or the Tomcat's servlet in both scenarios, the results are the same: both create() and hello() get called without a problem, while the latter method prints out correct principal name. however, Weblogic hosting the unsecured servlet behaves differently (and undesirably). in the first scenario where all methods are secured, create() is allowed to be executed, but calling hello() results in an insufficient privileges error. in the 2nd scenario, where only create() method is secured, Weblogic allows hello() to be called without a problem. however, the principal that it returns is "anonymous". my question is how is it possible for not only Tomcat, but even a standalone class to call a secured method without the use of PrivilegedAction and get back a correct principal? yet when absolutely identical code is called from another Weblogic instance, i cannot even obtain a correct principal despite the use of PrivilegedAction!!!
thanks!

Hi "werwer" (or is that "wer" :-),
I haven't checked the forum archives, so I may have already mentioned
this to you (or I may have already mentioned it to someone else
on this forum), but there are many resources available on the
Internet that can answer nearly all your J2EE related questions!
I would like to mention two. (If you already know about them, then
I suggest you study them. If you have already studied them and
still don't know the difference between a stateful and a stateless
session bean, then perhaps you can be a bit more specific about
what, in particular, you are having difficulty with.)
1. "Mastering Enterprise JavaBeans" by Ed Roman
A book that you can download as a PDF file.
http://www.theserverside.com/books/masteringEJB/index.jsp
(Also look for the companion book -- at the same URL -- "EJB
Design Patterns")
Note that you need to become a "member" in order to download
these books -- but registration is free.
2. "Enterprise Java Beans, 3rd Edition" by Richard Monson-Haefel
This is an online book -- that you cannot download!
http://safari.informit.com/main.asp?bookname=entjbeans3
Note that "Safari" (at "InformIT") are offering a free, two-week
trial subscription.
Hope this helps you.
Good Luck,
Avi.

Similar Messages

  • EjbHome method vs stateless bean method

    Does the ejbHome<method> and stateless bean method share the same concept?

    Hi,
    Basically the ejbHome<Method> will be the call onto the home object and it inturn uses the bean to make a call where as the stateless session bean method will be a call onto the ejb object.
    So in the client code making a call you just make a looup and call the ejbHome<method> whereas in case of stateless session bean , you need to make a lookup and create and then use the object.
    Hope this helps...
    Bhgaya

  • How to get stateful and stateless session bean in second jsp

    I create stateful session bean in the first jsp, then how can I get the stateful session bean in the second jsp? I find that somebody store the bean in HttpSession.
    If I store the stateful session bean in HttpSession, then I can get it in the second jsp. My problem is that I can store the stateless session bean in HttpSession, and get it in the second jsp. Then, both stateful and stateless can maintain the state in the second jsp. What is the difference between stateful and stateless session bean in this case ?
    I understand the definition of stateful and stateless session bean, but I'm confuse how to use session bean. Can anyone provide sample jsp to show difference of stateful and stateless? How the stateful session bean can maintain the state for the client?

    Greetings,
    I create stateful session bean in the first jsp, then how can I get the stateful session bean in the
    second jsp? I find that somebody store the bean in HttpSession.Which is the correct scope for sharing client-specific data when 'request' scope is insufficient.
    If I store the stateful session bean in HttpSession, then I can get it in the second jsp. My problem is
    that I can store the stateless session bean in HttpSession, and get it in the second jsp. Then, bothWhy is that a "problem"? Does your application not require the stateless bean to be shared? If so, then don't store the EJBObject reference in the session...
    stateful and stateless can maintain the state in the second jsp. What is the difference betweenWhat do you mean by this exactly?..
    stateful and stateless session bean in this case ?Statefulness of session beans is in regard to maintaining client state (er, in all cases). If your "stateless" bean is receiving information from the client (i.e. its caller) - either through a create method or a business method - and that information is available (retrievable from the bean) on subsequent method calls, then that bean is, in fact, stateful - regardless of how it is deployed.
    I understand the definition of stateful and stateless session bean, but I'm confuse how to use
    session bean.The correct question, it here seems, is "when" to use which type... Use a "stateful" bean when information about (from) the client (i.e. the caller) must be maintained across method calls of the bean. Use a "stateless" bean for general business methods that do not depend on "prior knowledge" of the client (i.e. the caller).
    Can anyone provide sample jsp to show difference of stateful and stateless? How the statefulA "sample JSP" would yield nothing additional... The semantics of calling, using, and "persisting", bean references are always the same - regardless of type or class. However, the reason(s) for using one over the other depends entirely on the needs of your application.
    session bean can maintain the state for the client?I recommend that you spend more time learning about EJBs generally. In particular, it seems you require more fundamental understanding of their scope and lifecycle. Refer to sections 4, 6, and 7 of the EJB 2.0 Specification.
    Regards,
    Tony "Vee Schade" Cook

  • Stateless and Stateful beans.

    Please tell me what are the important differences between stateless, and stateful beans.
    Thanks in advance.

    See this thread
    http://forum.java.sun.com/thread.jsp?forum=13&thread=529706&tstart=15&trange=15

  • Difference between stateful and stateless session beans

    can any body explain simply what is the difference between stateful and stateless session beans? also in what kind of situations we can use these.

    Hi
    This is the classificatio os Session Bean.
    (1) Statfull
    (2) Stateless
    Stateful means u will persists the state of the object.
    USESE:
    In a Banking system u can use the statful session just for maintaing the
    state.
    (2) STATELESS: that's mean u do't want to persists any state of the object. that's mean a single Request is coming ,do the desire and give the output.
    EX: A Credit Card System is the Example of Stateless.
    May it will helpfull to understands u. if any need write here
    saM

  • Stateless bean instance cache and usage algorithm

    I have two clients C1 and C2 which call the same bean B1. Is it possible to control
    the instance that gets bound to each client. I dont want to use stateful beans
    as it affects performance and the beans are inherantly stateless.

    Why do you want to do that? If you use SFSB and have no state most of the overhead
    associated with state management would not be there. However the scaling that
    comes with spraying would be gone. You would not have it with SLSB either if you
    tie it to the client.
    However if you implement a custom call router you might be able to bind SLSB to
    a client. Keep in mind DGC might collect your bean.
    S
    S
    "Ashok" <[email protected]> wrote:
    >
    I have two clients C1 and C2 which call the same bean B1. Is it possible
    to control
    the instance that gets bound to each client. I dont want to use stateful
    beans
    as it affects performance and the beans are inherantly stateless.

  • Exception while getting the server instance. Stateless bean problem

    Hi,
    New to OC4J, I'm moving an ear that was running ok under jboss.
    1- The wep app deploys. This is a piece of code inside the init() method of a struts plugin:
         System.out.println("0");
         AddressFacadeHome addressFacadeHome = HomeFactory.getAddressFacadeHome();
         System.out.println("1.0");
         AddressFacade addressFacade = addressFacadeHome.create();
         System.out.println("1.5");
    2- The code is run when the web app is initialized. This is the error message I get. system.out show that the error occurs on addressFacadeHome.create().
    AddressFacade is a remote/local stateless bean. HomeFactory returns the jndi lookup/narrow of the remote object.
    0
    1.0
    caught exception while getting the server instance null
    java.lang.NullPointerException
    com.evermind.security.User com.evermind.server.ThreadState.getCurrentUser()
    ThreadState.java:637
    com.evermind.security.User com.evermind.server.ThreadState.getUser()
    ThreadState.java:371
    fda.common.address.ejb.interfaces.AddressFacade AddressFacadeHome_StatelessSessionHomeWrapper7.create(
    AddressFacadeHome_StatelessSessionHomeWrapper7.java:66
    void fda.web.oaa.struts.plugin.ApplicationInit.init(org.apache.struts.action.ActionServlet, org.apache
    .struts.config.ModuleConfig)
    void org.apache.struts.action.ActionServlet.initModulePlugIns(org.apache.struts.config.ModuleConfig)
    ActionServlet.java:1105
    void org.apache.struts.action.ActionServlet.init()
    ActionServlet.java:468
    void javax.servlet.GenericServlet.init(javax.servlet.ServletConfig)
    GenericServlet.java:258
    com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.loadServlet(com.
    evermind.util.ByteString)
    HttpApplication.java:1956
    com.evermind.server.http.ServletInstanceInfo com.evermind.server.http.HttpApplication.findServlet(com.
    evermind.util.ByteString)
    HttpApplication.java:4355
    void com.evermind.server.http.HttpApplication.initPreloadServlets()
    HttpApplication.java:4455
    void com.evermind.server.http.HttpApplication.initDynamic(com.evermind.server.http.HttpApplicationConf
    ig)
    HttpApplication.java:662
    void com.evermind.server.http.HttpApplication.<init>(com.evermind.server.Application, com.evermind.ser
    ver.http.HttpSite, com.evermind.server.http.HttpApplicationConfig, java.lang.String, java.lang.String, boolean
    My guess is that it's a jaas issue (because i see security and getCurrentUser), but at init time, no user is authenticated.
    Any clue would be very much appreciated. Let me know if I can provide anything else, such as deployment descriptors.
    Thanks,
    Christophe.

    After spending some time on this, I looked at the source code for com.evermind.server.ThreadState
    This is the code that throws the exception:
    if(applicationThread != null && applicationThread.httpHandler != null && applicationThread.servletInfo != null)
    try
    server = applicationThread.httpHandler.request.getApplication().getApplication().getServer();
    catch(Throwable t)
    System.out.println("caught exception while getting the server instance " + t.getMessage());
    t.printStackTrace(System.out);
    It looks like this method expects a httpRequest, and would find null because I'm in the servlet.init()
    (at least, that's my interpretation)
    I tested my code (the remoteFacade.create()) inside of a jsp, and it worked...
    So, the next logical question is:
    Can I make EJB calls from within the init method of a servlet? (or more specifically from a struts plugin, which I believe should be more or less the same thing)
    If so, do I need to take extra steps?
    Again, any experience/help on this will be much appreciated.
    Thanks,
    Christophe.

  • EJB 3.0 stateless bean + web client (beginner)

    Hello,
    I've just read the Sun tutorial on EJBs in Java EE 5 and I'm trying to get something nice and simple to work. My code is below:
    Bank.java:
    package beans;
    import javax.ejb.Remote;
    @Remote
    public interface Bank {
         public void transfer(long source, long destination, long amount);
    }BankBean.java:
    package beans;
    import javax.ejb.EJBException;
    import javax.ejb.Stateless;
    @Stateless
    public class BankBean implements Bank {
         public void transfer(long source, long destination, long amount)
              System.out.println("This method is not yet implemented.");
              throw new EJBException("Method not implemented.");
    }index.jsp (web project):
    <%!
    private Bank bank = null;
    public void jspInit()
        try {
            InitialContext ic = new InitialContext();
            bank = (Bank) ic.lookup(Bank.class.getName());
        } catch (Exception ex) {
            System.out.println("Couldn't create bean." + ex.getMessage());
    %>Everything compiles with no errors or warnings, but an exception is thrown. The message is "beans.Bank not found".
    I have not modified any .xml files, I don't recall the tutorial saying I have to.
    I'm using Eclipse 3.2 WTP and it doesn't recognize that I have any Session beans... not 100% sure that EJB 3.0 is supported by it. I ended up creating a basic Java project to store the beans because an EJB project was saying that I need at least one bean.
    Thank you in advance for suggestions.
    Pavel

    While looking up why don't you use the fully
    qualified jndi name"java:/comp/ejb...."?
    What's the benefit of that?It's portable. Any direct access of a global JNDI namespace is not portable.
    Also, it's "java:comp/env", not "java:/comp/env".
    >
    Is it possible to use annotations in JSPs?No, annotations are not supported in JSPs for Java EE 5. In the web tier
    they can be used in certain managed classes such as servlets.
    Regarding your original posting, how exactly did you deploy the ejb? If you
    got a message saying the ejb-jar had no ejbs, that sounds like the root of
    the problem. If the ejb-jar only contains a single EJB 3.0 bean and that
    bean uses EJB 3.0 annotations instead of a deployment descriptor, make
    sure there is no ejb-jar.xml. It's possible that Eclipse packaged an
    EJB 2.1 - based ejb-jar.xml descriptor inside the ejb-jar. In that case,
    the app server will assume it is an EJB 2.1 app and not process any
    annotations.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • EJB 3.0 Stateful bean not saving state while Stateless bean is !!!

    My Stateless bean is as follow:
    package test;
    import javax.ejb.Stateless;
    @Stateless(mappedName = "StatelessBean")
    public class StatelessBean implements StatelessBeanRemote {
         int counter;
         public void increment(){
              System.out.println("Stateless counter value:"+counter);
              counter++;
    My Stateful bean is as follow:
    package test;
    import javax.ejb.Stateful;
    @Stateful(mappedName = "StateFulBean")
    public class StateFulBean implements StateFulBeanRemote {
         int counter;
         public void increment(){
              System.out.println("Stateful counter value:"+counter);
    Client is as follows:
    package test;
    import java.util.Hashtable;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    public class TestClient {
         public static void main(String[] args) {
              Hashtable hashtable = new Hashtable();
              hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
              hashtable.put(Context.PROVIDER_URL, "t3://localhost:7001");
              InitialContext ic;
              try {
                   ic = new InitialContext(hashtable);
                   StateFulBeanRemote stateFulBeanRemote = (StateFulBeanRemote)ic.lookup("StateFulBean#test.StateFulBeanRemote");
                   stateFulBeanRemote.increment();
                   StatelessBeanRemote statelessBeanRemote = (StatelessBeanRemote)ic.lookup("StatelessBean#test.StatelessBeanRemote");
                   statelessBeanRemote.increment();
              } catch (Exception e) {
                   e.printStackTrace();
    The output i am getting after running the client twice is as follows:
    //first time
    Stateful counter value:0
    Stateless counter value:0
    //second time
    Stateful counter value:0
    Stateless counter value:1
    Shouldn't the counter values be incremented in case of Stateful bean and remain the same for Stateless bean. But the output that I am getting is the complete opposite !!!
    Can anyone please explain this confusing behavior of stateless and stateful ejb 3.0 beans.

    868664 wrote:
    Can anyone please explain this confusing behavior of stateless and stateful ejb 3.0 beans.It is very simple: a stateless bean is ASSUMED to be stateless; you cannot keep state in a stateless bean as a contractual rule. That doesn't mean that you will fail to keep state in them at least for a little while, they are still only Java objects. Generally stateless EJBs are pooled, so you may get the same instance each time you use such an EJB, but you may just get another one. It is not dependable and the rules say don't do it - so don't do it.
    A stateful bean is tied to a single client, and so can be used by a client to keep state in it. Since You are running the client application twice you are operating with two different clients and so you will get a new stateful bean each time and your code will keep printing 0. However there is also a bug in your code:
    public void increment(){
    System.out.println("Stateful counter value:"+counter);
    }You are not incrementing anything.

  • CacheFullException with Stateless bean

    Hallo everbody,
    I have a problem with a Stateless bean the log file give me this error:
    javax.ejb.EJBException: Exception during transition from pooled to ready:
    - with nested exception:
    [weblogic.ejb20.cache.CacheFullException: Cache is at its limit of: '100' *active*
    beans.]
    I use this bean for several action, and just for an action I have this error.
    What I can't underastand that Stateless bean get with the session and as the user
    close the session the Bean have to expire, isn'it? So can't uderstand while 100
    Bean still on the cache.
    Could anyone help me?
    Thank's a lot
    Fausta

    1. check thread dump ... any threads actually still busy?
    2. is it stateful or is it stateless? I don't mean how do you deploy it, but
    I mean which is it really? does it have any state?
    3. always call remove() ... this isn't the problem (Weblogic doesn't require
    remove()) but you should do so anyway.
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    Clustering Weblogic? You're either using Coherence, or you should be!
    Download a Tangosol Coherence eval today at http://www.tangosol.com/
    "Sachin Shah" <[email protected]> wrote in message
    news:[email protected]..
    >
    Hi,
    I have a statelesss session bean which i m using in the application.Initially
    this bean was stateful bean but due to problems of timeout it was changedto stateless
    bean. The problem is sometimes when i view the statistics from console, ifind
    that there are max 20 beans allowed and all 20 are in use. Because ofwhich no
    user can work further and i have to shutdown the server. I fail tounderstand
    this cause being a stateless session bean it should be released (returnedto free
    pool) as soon as the method is over. So why this behaviour. Any idea.
    Thanks in Advance

  • Stateless Bean - scope of instance variable in EJB Timer call back function

    Hi,
    I would like to know on the scope of an instance variable of a Stateless Bean object,
    when used in a EJB Timer call back.Let me explain this in more detail below.
    I have a requirement to use a EJB Timer.
    For this, I have created a stateless object since Timer creation needs to be done
    from a stateless bean. I have a member variable "count" of the stateless bean class.
    In the timer call back(ejbTimeout), I am able to use this count variable during
    each time of the call back, and the value of this variable is also updated properly.
    I have a few queries with respect to the above behaviour:
    1) Does stateless bean object not get destroyed once the Timer is created from the Bean?
    2) If the Bean object is not destroyed, then when does the bean object get destroyed?
    3) If both (1) and (2) are not true, then can anyone explain on how the above behaviour is possible?
    Thanks in advance,
    Ulrich

    Hi Ulrich,
    The ejb timer is associated with the stateless session bean component, not with a particular bean instance. There is no formal relationship between the bean instance that called createTimer() and the bean instance on which the timer callback happens. If they're the same in your test run that's just a coincidence and not something your application should be depending on.
    In the stateless session bean model, the container can create and destroy stateless session bean instances at any time. The container is free to pick any stateless session bean instance to service any client invocation or timer callback. If you need to pass context into a timer callback, one way to do it is via the timer "info" object. However, the info object is immutable so it wouldn't be a good match for a counter. You could of course always just use a database for any necessary coordinated state.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Performance of Session Stateless Bean in WebSphere with connection to DB

    Im using WebSphere Advanced Single Server Edition Version 4.0.1. and a WebSphere DataSource to get my connections to Microsoft SQL 2000 (using netdirect's JSQLDriver).
    For the EJB I set the transaction to 'requieresNew'.
    For testing purposes I had been testing some code I'll be using in a Session Stateless Bean inside a servlet's method. In my servlet I use one single connection and preparedStatements to improve performance.
    When I test it on the Servlet, this process takes around 3 minutes to complete, but when I put this code inside a Session Stateless Bean and call it from this servlet's method, it takes around 30 minutes to complete!. How is this possible?!
    Worst of all, when the EJB ends and the process returns to the Servlet, it throws me this exception.
    com.ibm.websphere.ce.cm.StaleConnectionException: class com.ibm.ejs.cm.proxy.PreparedStatementProxy is closed.
    The code uses some utilities from a Framework we created, but I really doubt it affects the performance since I put such classes in a jar file and the EJB is accessing such classes correctly.
    I thought that maybe I was missing something related with how I get the connection inside the EJB, but I had no luck trying to figure this out.
    This is the code in my EJB, commented code was in use when this code was tested in the method of the servlet (some code has been removed or modified, so I just left the 'main' body of the code):
    package cmx.ejb;
    import cmx.common.*;
    import java.util.*;
    import qsi.sys.db.*;
    import qsi.sys.util.*;
    import java.rmi.*;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.util.*;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.*;
    import javax.sql.DataSource;
    * Bean implementation class for Enterprise Bean: SimuladorEJB
    public class SimuladorEJBBean implements javax.ejb.SessionBean {
         private javax.ejb.SessionContext mySessionCtx;
    private Context ctx;
    private DataSource ds;
    private static final int TCONSUMO = 4;
    private static final int CARACEQ = 6;
    private static final int PPRODUC = 9;
    private static final int PPUNTA = 12;
    private static final int UTONHR = 8;
    private static final int TPRODUCC = 3;
    private Vector val = null;
    private Vector vecArea = null;
    private String query;
    private Object[] params;
    private int numAreas;
    private int vSecDetHE;
    //All the prepared statements I'll use in my process
    private PreparedStatement pstmSelectSerial = null;
    private PreparedStatement pstmUpdateSerial = null;
    private PreparedStatement pstmgetPPEquipos = null;
    private PreparedStatement pstmgetTransfers = null;
    private PreparedStatement pstmaddRProduccion = null;
    private PreparedStatement pstmupdInventario = null;
    private PreparedStatement pstmgetServicios = null;
    private PreparedStatement pstmaddConsumo = null;
    private PreparedStatement pstmgetAreaEquipos = null;
    private PreparedStatement pstmfindCE = null;
    private PreparedStatement pstmcontEventoLogEq = null;
    private PreparedStatement pstmaddLog = null;
    private PreparedStatement pstmfindCaract = null;
    private PreparedStatement pstmfindComposicion = null;
    private PreparedStatement pstmfindCombAlt = null;
    private PreparedStatement pstmaddInventarioH = null;
    private PreparedStatement pstmgetAlmMatREM = null;
    private PreparedStatement pstmfindAlmacen = null;
    private PreparedStatement pstmcontEventoLogAlm = null;
    private PreparedStatement pstmgetAlmacenes = null;
    private PreparedStatement pstmfindInvHora = null;
    private PreparedStatement pstmgetPeriodoHorario = null;
    private PreparedStatement pstmgetProgramaCE = null;
    private PreparedStatement pstmgetProgramaPP = null;
    private PreparedStatement pstmgetProgramaParo = null;
    private PreparedStatement pstmgetPrograma = null;
         * getSessionContext
         public javax.ejb.SessionContext getSessionContext() {
              return mySessionCtx;
         * setSessionContext
         public void setSessionContext(javax.ejb.SessionContext ctx) {
              mySessionCtx = ctx;
         * ejbActivate
         public void ejbActivate() {
         * ejbCreate
         public void ejbCreate() throws javax.ejb.CreateException {
    System.out.println("ejbCreate()");
    try {
    Hashtable parms = new Hashtable();
    parms.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
    ctx = new InitialContext(parms);
    ds = (DataSource)ctx.lookup("jdbc/datasource");
    }catch (Exception e){
    e.printStackTrace();
         * ejbPassivate
         public void ejbPassivate() {
         * ejbRemove
         public void ejbRemove() {
    System.out.println("ejbRemove()");
         pstmSelectSerial = null;
         pstmUpdateSerial = null;
         pstmgetPPEquipos = null;
         pstmgetTransfers = null;
         pstmaddRProduccion = null;
         pstmupdInventario = null;
         pstmgetServicios = null;
         pstmaddConsumo = null;
         pstmgetAreaEquipos = null;
         pstmfindCE = null;
         pstmcontEventoLogEq = null;
         pstmaddLog = null;
         pstmfindCaract = null;
         pstmfindComposicion = null;
         pstmfindCombAlt = null;
         pstmaddInventarioH = null;
         pstmgetAlmMatREM = null;
         pstmfindAlmacen = null;
         pstmcontEventoLogAlm = null;
         pstmgetAlmacenes = null;
         pstmfindInvHora = null;
         pstmgetPeriodoHorario = null;
         pstmgetProgramaCE = null;
         pstmgetProgramaPP = null;
         pstmgetProgramaParo = null;
         pstmgetPrograma = null;
    public void GenerarSimulacion(int pidSimulacion, String pfini, String pffin, int cveEntidad, int cveUsuario) throws Exception{
    System.out.println("GenerarSimulacion()");
    System.out.println("***Simulacion " + pidSimulacion + " en proceso...***");
    Calendar inicioProceso = Calendar.getInstance();//Tiempo en que empezo el Proceso
    Calendar finProceso = null;//Tiempo en que termino el Proceso
         Connection cnn = null;
    //boolean autoCommit = false;
         try{
         cnn = ds.getConnection();
    autoCommit = cnn.getAutoCommit();
    cnn.setAutoCommit(false);
         cnn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    pstmSelectSerial = cnn.prepareStatement("select iValor from CatConsecutivo where vcConsecutivo=?");
    pstmUpdateSerial = cnn.prepareStatement("update CatConsecutivo set iValor = iValor+1 where vcConsecutivo=?");
    pstmgetPPEquipos = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getPPEquipos"));
    pstmgetTransfers = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getTransfers"));
    pstmaddRProduccion = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.addRProduccion"));
    pstmupdInventario = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.updInventario"));
    pstmgetServicios = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getServicios"));
    pstmaddConsumo = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.addRConsumo"));
    pstmgetAreaEquipos = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getAreaEquipos"));
    pstmfindCE = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findCE"));
    pstmcontEventoLogEq = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.contEventoLogEq"));
    pstmaddLog = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.addLog"));
    pstmfindCaract = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findCaract"));
    pstmfindComposicion = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findComposicion"));
    pstmfindCombAlt = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findCombAlt"));
    pstmaddInventarioH = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.addInventarioH"));
    pstmgetAlmMatREM = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getAlmMatREM"));
    pstmfindAlmacen = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findAlmacen"));
    pstmcontEventoLogAlm = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.contEventoLogAlm"));
    pstmgetAlmacenes = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getAlmacenes"));
    pstmfindInvHora = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.findInvHora"));
    pstmgetPeriodoHorario = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getPeriodoHorario"));
    pstmgetProgramaCE = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getProgramaCE"));
    pstmgetProgramaPP = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getProgramaPP"));
    pstmgetProgramaParo = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getProgramaParo"));
    pstmgetPrograma = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getPrograma"));
    pstmgetAreaEquipos = cnn.prepareStatement(Manager.getParameter("cmx.admin.inicioSesion.getAreaEquipos"));
    Map hmEqMat = null;
    Iterator itEqMat = null;
    Map.Entry meEqMat = null;
    Map hmInvAlm = null;
    Iterator itInvAlm = null;
    Map.Entry meInvAlm = null;
    Map hmPunta = null;
    Iterator itPunta = null;
    Map.Entry mePunta = null;
    Iterator itPuntaEq = null;
    HashMap hmPuntaEq = null;
    Vector vecPuntaEq = null;
    Iterator itPPEq = null;
    HashMap hmPPEq = null;
    Vector vecPPEq = null;
    Iterator itCar = null;
    HashMap hmCar = null;
    Vector vecCar = null;
    Iterator itLog = null;
    HashMap hmLog = null;
    Vector vecLog = null;
    Iterator itCA = null;
    HashMap hmCA = null;
    Vector vecCA = null;
    Iterator itCom = null;
    HashMap hmCom = null;
    Vector vecCom = null;
    Iterator it = null;
    HashMap hm = null;
    Vector vecEv = null;
    Iterator itEq = null;
    HashMap hmEq = null;
    Vector vecEq = null;
    Vector vecSim = null;
    Date d;
    String sDSim = "";
    Date dDiaPrevio;
    String sDiaPrevio = "";
    String consulta;
    int vContador= 0;
    int hr=0;
    long vDiaPrevio = 0;
    Integer idInvH;
    Integer idProd;
    Integer idCons;
    Integer idLog;
    int vCont = 0;
    int vCiclo = 0;
    int vArea = 0;
    int vAreaAct = 0;
    int vPuntaEquipo = 0;
    // Periodo de Simulacion
    long fini = getCurrDate(pfini);
    long ffin = getCurrDate(pffin);
    // Variables Generales
    int vSecuencial = 0;
    int vEvento = 0;
    float vCostoE = 0;
    int vAlmacenREM = 0;
    // Variables de Transferencia
    float vCantidad = 0;
    int vTipoMov = 0;
    int vUMedida = 0;
    int vAlmacenTr = 0;
    float vNIni = 0;
    float vNMin = 0;
    float vNMax = 0;
    float vNAct = 0;
    // Variables de Equipos
    int vPPMaterial = 0;
    int vPPEquipo = 0;
    int vPPArea = 0;
    int vMaterial = 0;
    int vCaractEq = 0;
    int vParo = 0;
    int vEstatusParo = 0;
    int vEstatus = 0;
    float vMinPunta = 0;
    float vPorcPunta = 0;
    float vProporcion = 0;
    float vTPH = 0;
    float vGasto = 0;
    float vKwNoProd = 0;
    float vKwProd = 0;
    int vAlmacen = 0;
    // Variables de Composicion de Materiales
    int vMaterialCom = 0;
    float vPorcCom = 0;
    float vFactorCC = 0;
    int vTipoMovCom = 0;
    int vUMedidaCom = 0;
    int vAlmacenCom = 0;
    float vNIniCom = 0;
    float vNMinCom = 0;
    float vNMaxCom = 0;
    float vNActCom = 0;
    int vMaterialCA = 0;
    int vUMedidaCA = 0;
    int vAlmacenCA = 0;
    float vNIniCA = 0;
    float vNMinCA = 0;
    float vNMaxCA = 0;
    float vNActCA = 0;
    int vOk=0;
    int h=0;
    boolean vbOk=false;
    boolean swArea=true;
    Calendar dtH1;
    vecSim = new Vector();
    vecSim.add(new Integer(pidSimulacion));
    for (long ld=fini; ld<=ffin; ld=getNextDate(new Date(ld), 1))
    {   d = new Date(ld);
    //The process which calls find(), upd(), AplicaEvento() and GetCostoEnergia() methods several times.
    //The methods find() and upd() uses a util class (DataDB) which basically assigns the params to the PreparedStatement and executes it, returning the results in a Vector.
    } // for ld : Dia de Simulacion
    //Cerrar la transaccion
    }catch (Exception e){
              System.out.println("rollback...");
                   mySessionCtx.setRollbackOnly();
         System.out.println("rollback ok!");
    System.out.println(e.toString());
                   throw e;
    }finally{
    finProceso = Calendar.getInstance();
    finProceso.setTime(new java.util.Date(finProceso.getTime().getTime() - inicioProceso.getTime().getTime()));
    System.out.println("***Simulacion " + pidSimulacion + " procesada en: " + finProceso.get(Calendar.MINUTE) + ":" + finProceso.get(Calendar.SECOND) + "." + finProceso.get(Calendar.MILLISECOND) + ".***");
    try {
    if (cnn!=null && !cnn.isClosed()) {
              System.out.println("close ok?");
    cnn.close();
                   System.out.println("close ok!");
    }catch (SQLException sqle){
    sqle.printStackTrace();
    System.out.println("commit ok?");
    cnn.commit();
    System.out.println("commit ok!");
    }catch (Exception e){
    e.printStackTrace();
    System.out.println(e.toString());
    try {
    if (cnn!=null && !cnn.isClosed()) {
                   System.out.println("rollback ok?");
                             cnn.rollback();
              System.out.println("rollback ok!");
    }catch (SQLException sqle){
    sqle.printStackTrace();
    }finally{
    finProceso = Calendar.getInstance();
    finProceso.setTime(new java.util.Date(finProceso.getTime().getTime() - inicioProceso.getTime().getTime()));
    System.out.println("Simulacion procesada en: " + finProceso.get(Calendar.MINUTE) + ":" + finProceso.get(Calendar.SECOND) + "." + finProceso.get(Calendar.MILLISECOND) + ".***");
    try {
    if (cnn!=null && !cnn.isClosed()) {
                   System.out.println("autocommit ok?");
                   cnn.setAutoCommit(autoCommit);
              System.out.println("autocommit ok!");
              System.out.println("close ok?");
    cnn.close();
                   System.out.println("close ok!");
    }catch (SQLException sqle){
    sqle.printStackTrace();
    private float GetCostoEnergia(float pfKw, long plFecha, int piHora,int cveEntidad) throws Exception {
    float exito = -1;
    //calculations and has access to DB throught method find()
    return exito;
    private int AplicaEvento(int pidMaterial, int pidEvento, int pidSecuencial, int pidSimulacion, long plFecha, int piHora) throws Exception {
    int exito = -1;
    //calculations and has access to DB throught method find()
    return exito;
    private Iterator find(PreparedStatement pstm, Vector values) throws Exception {
    params = (values!=null)? values.toArray() : null;
    Vector data = DataDB.executeQuery(pstm, params); //This util class is in a external jar file, such util basically assigns the params to the PreparedStatement and executes it, returning the results in a Vector.
    return data.iterator();
    private int upd(PreparedStatement pstm, Vector values) throws Exception {
    params = values.toArray();
    return DataDB.executeUpdate(pstm, params); //This util class is in a external jar file, such util basically assigns the params to the PreparedStatement and executes it.
    Help will be REALLY appreciated!
    Thanks in advance.

    Thanks Paul for your comments.
    In fact, I call my EJB in the servlet just once. Im sure calling the same EJB. My project requieres it to be stateless.
    This is my last log
    1/2/03 13:15:00:481 CST] 17fac55b SystemOut U -ejbCreate()-
    [1/2/03 13:15:00:591 CST] 17fac55b SystemOut U jdbc/xa/oye
    [1/2/03 13:15:00:651 CST] 17fac55b SystemOut U -GenerarSimulacion()-
    [1/2/03 13:15:00:741 CST] 17fac55b SystemOut U ***Simulacion 32 en proceso...??***
    [1/2/03 13:15:01:012 CST] 17fac55b SystemOut U JSQLConnect(2.2721) Trial license - expires on:Tue Jan 07 13:01:32 CST 2003, unlimited connections
    [1/2/03 13:15:01:092 CST] 17fac55b SystemOut U Connection OK!
    [1/2/03 13:15:01:392 CST] 17fac55b SystemOut U PreparedStatements OK!
    [1/2/03 13:15:01:402 CST] 17fac55b SystemOut U Comenzando Sim...
    I forgot to mention that I create a connection (autocommit false) at the begining of my servlet, which I use throught all the servlet, then I call the EJB, and after the EJB succeds I also close the transaction in the Servlet (to commit what is on the servlet, not the EJB). Thats why I set the transaction in the EJB to requiresNew, so after the EJB ends it commits its own transaction, Am I right?.
    The Exception I get I think its because the connection used in the servlet timed out while waiting for the EJB to finish.
    This issue has become urgent, so please if you know why I have this problem reply ASAP.
    Thanks!

  • Stateless bean giving error when deployed through j2ee 1.3RI

    I have written a simple stateless bean and deployed through j2ee 1.3 RI
    Context initial = new InitialContext(h);
    Object obj = initial.lookup("SampleObject"); // SampleObject -jndi name
    SampleHome home = (SampleHome)PortableRemoteObject.narrow(obj, SampleHome.class);
    But when running the Client , getting the error
    java.lang.ClassCastException
    at com.sun.corba.se.internal.javax.rmi.PoartableRemoteObject.narrow(Unknown Source)
    at javax.rmi.PortableRemoteObject.narrow(Unknown Source)     at SampleClient.main(SampleClient.java:27)
    Is it a system error or what

    Hi sessionbean,
    The most common cause of this exception is when the RMI-IIOP stubs are not found within the client's classpath. The client stubs are returned from the deployment step.
    Also, it's better to use the no-arg initial context constructor "new InitialContext()" and let the J2EE 1.3 RI code bootstrap the correct naming service.
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Unable to rollback using BMT in a stateless bean

    Hi,
    My stateless bean contains the following testing code
    UserTranaction ut = null;
    try{
    ut = context.getUserTransaction();
    ut.begin();
    // get database connection from OracleDataSource
    // via container
    // update a recored in db
    if (true)
    throw new Exception();
    ut.commit();
    } catch (Exception e){
    ut.rollback();
    } finally {
    // close connection
    I am using oracle 817 jdbc driver and when I execute the method,
    the changes in DB are not rolledback and there is no exception
    thrown. My questions are
    1). Is BMT really work in oc4j? Anyone try before?
    2). Is there any additional conditions/setting need to be done
    in order to make BMT work? such as dataSource setting, database
    configuration...
    3). Could anyone provide sample code with related settings?
    (especially what datasoure u are using)
    Thank you very much!!!

    Have you already tried to load the class like this:
    Thread.currentThread().getContextClassLoader.loadClass(actionName);
    Instead of using the same classloader that loaded your bean implementation, it uses the classloader given to the executer thread as the context classloader.
    (In many cases this will be the same, but I don't know how this is done in the implementation of your container).

  • How many ejbCreate() can be in Session and Entity Bean???

    Hi,
    How many ejbCreate() method can be in a Session and Entity
    Bean???
    How many can be in Stateless and Stateful SessionBean???
    How many can be in CMP and BMP SessionBean???
    Thanks,
    JavaCrazyLover

    How many ejbCreate() method can be in a Session
    ion and Entity
    Bean???For Stateful Session Beans and Entity Beans, as many as you'd like.
    Stateless Session beans can only have one, since their ejbCreate methods can not take any parameters.
    >
    >
    How many can be in CMP and BMP SessionBean???If you mean CMT/BMT(Container-Managed transactions / Bean-Managed Transactions), then
    the answer is the same. The create method requirements are independent of the transactional nature of the bean.
    If you really mean CMP/BMP(Container-Managed Persistence / Bean-Managed Persistence) , it doesn't apply to session beans, only entity beans. However, even for entity beans, CMP vs. BMP has no bearing on the rules regarding # of create methods.
    --ken
    >
    >
    Thanks,
    JavaCrazyLover

Maybe you are looking for

  • How to Capture Button event on TrainBean navigation

    Hi All i m being required to capture a button event in train bean Navigation, i m doing customization in Iexpense Module,here in Create IExpenseReport i need to capture the events of Remove,Return etc.how is it possible any clue would be very helpful

  • Problem in MB_MIGO_BADI, Reference Document No.(MSEG-LFBNR) field is blank

    Hi All, I have implemented the MB_MIGO_BADI. At the time of Goods Receipt a Custom tab is triggering only for a set of vendors as per my requirement. The problem is, in the Item level Ref. Docu field(MSEG-LFBNR) is blank when ever it's triggers my cu

  • Installing J2SE

    Hey all, it's me perlgoodies but I forgot my password and can't change it because I didn't setup a password reminder thing. I formatted a few days ago and had to reinstall everything. Now I can't get javac to work, it keeps saying it's not a command

  • Printing HP3030

    I keeping getting a low memory warning from the printer.  Any ideas about this?

  • Fullscreen slideshow will not "slide" automatically

    To make it easy for my collegues to show a slideshow in full screen with 5 sec. delay and a soft transistion, I have made one in Acrobat and expect people to run it with 1 click in their Acrobat Reader X. It seems like I can store these parameters in