Session bean versus normal bean

Hi,
I am at design decision whether to uses a normal Java class or a stateless session bean. I basically need to get data in a list format (read only). I don?t have many users in the system. May be max 60 users online.
I am thinking of using a fast lane reader. For this I will use a helper class in my web layer maybe doing data access through a DAO. My friends say to use a session bean because of object pooling, clustering etc. I am still convinced a normal class will do. Please help me out with any advice.
Thanks,
Gavin

A Session Bean can be a fast lane reader if you want. The data-reading aspect relates more to Entity Beans than to Session Beans.
If you're simply after a snapshot of the data then I'd opt for a Session Bean that hits the database directly through a utility class (your fast lane reader).
EJBs are useful for providing configurable access to resources and get you security, transactional isolation, pooling etc.. These advantages carry an overhead - the EJB life-cycle - which can become prohibitive in some circumstances. However, you'd be unwise to throw away the benefits without first gauging the impact of this overhead.
It must be noted here that most of the benefits (except security) are probably of little interest to your situation; you don't really need much in the way of clustering or pooling as there's no state being maintained, transactional isolation isn't really relevant either. But then again, how else will you write a server-side component that accesses the database? Or are you going to access the database directly from the client (your web server)? Is the latter a good idea with your dataset? What does this do to your application's configuration? What are the security considerations? Is the number of users likely to increase in future?
There's no single answer to your problem as it will depend on many factors. I tend to opt for the simplest solution (Entity Beans for a small dataset or a Session Bean accessing the database for a large one) and defer optimisation until bottlenecks can successfully be measured.
Hope this helps.

Similar Messages

  • Call Bean from normal java class

    Dear Friends,
    Is it ok to call an entity bean or session bean frm normal Java class.
    (Java class is in the same application as the beans).
    Is there a special way to lookup the beans from normal java classes.
    Thanking You,
    Chamal.

    it is ok and very commonly done.
    Note that the simple java program must be running in the same local network. You cannot have the java program and EJBs distributed over internet. (I m not certain of it, but mostly I shoudl be correct. If you have the resources, try it out and let me know)
    In most of the cases, EJBs are called by
    1. A servlet
    2. Another EJB
    3. a simple java program.
    In the first 2 cases, you can go for Local Interfaces (more so in the second case than the first). The reason being that the the client and server will be in the same JVM (typically the Application server). Thus, in the first case, if the Web container and the ejb container are in the same app server, EJBs can be local.
    However, in the third case, it is unlikey that you will have the client runnng and the same jvm as the server, because the app server has its own jvm.
    sample code (this method is being called from the main method of a simple java program. it is self explanatory):
    public  void processRequestForSessionBean()
             System.out.println("REQUEST RECEIVED");
             try
                   Hashtable nameHashtable = new Hashtable();
                   nameHashtable.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
                   nameHashtable.put( Context.PROVIDER_URL, "t3://localhost:7001" );
                   InitialContext context = new InitialContext(nameHashtable);
                   System.out.println("created initial context");
                   Object lookupObject = context.lookup("CustomerBean");
                   System.out.println("Got the lookup object");
                   CustomerDataHome home = (CustomerDataHome) PortableRemoteObject.narrow(lookupObject,
                             Class.forName("com.shiv.business.CustomerDataHome"));
                   System.out.println("Home interface");
                   customerData = home.create();
                   System.out.println("Remote Interface");
                   addDataToSB(customerData);
                   ArrayList namesList = customerData.getNames();
                   System.out.println(namesList.toString());
                   //customerData.remove();             
              catch (Exception exception)
                   System.out.println("FATAL ERRORS");
                   exception.printStackTrace();
              }

  • How to set session attributes in a bean?

    How do I set a session attribute in a server-side bean?
    I'm not sure if I asked the question the right way. What I meant is, while it's easy to set session attributes in a JSP page (session.setAttribute("sessionname", "sessionvalue")), I'd want to set such an attribute within a server-side bean defined in this web application. But what is the syntax for doing it?

    Here a simple bean that stores something in the session and retrieves something from it.
    import javax.servlet.http.HttpSession;
    public class TestBean {
      private String value;
      public void doSomething(HttpSession session, int a, int b) {
        if (a+b > 0) {
          session.setAttribute("ab",Boolean.TRUE);
        } else {
          session.setAttribute("ab",Boolean.FALSE);
      public void init(HttpSession session) {
        if (session != null) {
          Boolean b = (Boolean)session.getAttribute("ab");
          if (b == Boolean.TRUE) {
            value = "a + b is greater than zero";
          } else {
            value = "a + b is not greater than zero";
        } else {
          value = "no session";
      public String getValue() {
        return value;
    }In your JSP, use something along the lines of :
    <%
      TestBean bean = new TestBean();
      bean.init(session);
      bean.doSomething(session,1,2);
    %>If your bean only lives during one request, you can pass the session to the constructor, which stores it in a private variable. This saves passing the session each time.
    Hope this helps,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can I set the value to a session bean from backing bean

    Hi Experts,
    How can I set the value to a session bean from backing bean where I have created getter and setter
    methods for that variable.
    Basically I am using ADFUtils class where I am able to get the value from session bean
    using following expression
    String claimType =
    (String)ADFUtil.invokeEL("#{ClaimValueObj.getClaimType}");
    Thanks
    Gayaz

    Gayaz,
    Wrong Post !!
    Post in JDeveloper and ADF
    Thanks
    --Anil                                                                                                                                                                                                                               

  • Hi, I have quick question about use of USEBEAN tag in SP2. When I specify a scope of SESSION for the java bean, it does not keep the values that I set for variable in the bean persistent.Thanks,Sonny

     

    Make sure that your bean is implementing the serializable interface and that
    you are accessing the bean from the session with the same name.
    Bryan
    "Sandeep Suri" <[email protected]> wrote in message
    news:[email protected]..
    Hi, I have quick question about use of USEBEAN tag in SP2. When I
    specify a scope of SESSION for the java bean, it does not keep the
    values that I set for variable in the bean persistent.Thanks,Sonny
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • Access session values in Managed Bean

    I want to acces session attribute values in my Managed Bean class.
    This is my code in SecurityPhaseListener.java class,
    HttpSession session = (HttpSession)facesContext.getCurrentInstance().getExternalContext().getSession(true);
    String isAuthorized = "false";
    session.setAttribute(isAuthorized, isAuthorized);
    This is my configuration for My managed bean in faces-config.xml class
    <managed-bean>
    <managed-bean-name>setNewDayBean</managed-bean-name>
    <managed-bean-class>com.hli.vipstar.uswm.setnewday.managedbean.SetNewDayBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    Now i want to access the attribute "isAuthorized" in my managed bean SetNewDayBean.java.
    How to do this?
    Any one help me...........

    The same way, but then using getAttribute() instead of setAttribute().
    Another -more clean- way is to use the ExternalContext#getSessionMap(). It will make your code independent from the session implementation used. You may find this article useful as well: http://balusc.blogspot.com/2006/06/communication-in-jsf.html

  • Session Bean calling entity bean

    Hi
    How does session bean calls entity bean in weblogic6.1
    Thanks

    have a look in the examples that come with weblogic
    "Anand" <[email protected]> wrote in message
    news:[email protected]..
    >
    >
    Hi
    How does session bean calls entity bean in weblogic6.1
    Thanks

  • How to get and set a session variable from backing bean?

    Hi im using Jdev 11.1.1.2.0 and i need to set and get a session variable from backing Bean.
    Any idea?

    the class :
    package arq.resources;
    import javax.faces.context.FacesContext;
    import javax.servlet.http.HttpSession;
    public class SesionSigef {
    public FacesContext context;
    public HttpSession session;
    public SesionSigef() {
    super();
    context = FacesContext.getCurrentInstance();
    session = (HttpSession)(context.getExternalContext().getSession(true));
    public Object getVariableSesion(String atributo){
    return session.getAttribute(atributo);
    public void setVariableSesion(String atributo,Object valor){
    session.setAttribute(atributo, valor);
    the example of use :
    SesionSigef se = new SesionSigef();
    DatosRec da = new DatosRec();
    da.setDocumentoCip("Aprobar");
    se.setVariableSesion("DatosRec", da);
    thanks
    Joaquin

  • Session Bean or Entity Bean

    I am building application in which I query 4 to 5 tables and display the reports
    . Presently I am using JSP and Servlets but would like to move to EJBs.
    What would be my best bet between Entity and Session beans ?
    Thanks in advance ..Frank

    Frank,
    You may want to peruse the following snippet from Sun's Java site on when to use
    session beans vs. entity beans
    http://java.sun.com/j2ee/j2sdkee/techdocs/guides/ejb/html/Overview4.html#9377
    Chuck Nelson
    Developer Relations Engineer
    BEA Technical Support

  • Weblogic 10.3.0 : Loosing a stateless session bean in the bean pool

    Hi,
    We have a strange situation where we loose a Stateless SessionBean in a Bean Pool in Weblogic 10.3.0 Since we only have one bean in the pool, this effectively hangs all incoming calls. We do not want more than one instance in the pool because of application restrictions.
    In the Weblogic admin console, we can see that there are 1 instance in the bean pool, 0 beans in use and 1 waiting incoming request.
    The question is, what can have caused the system to not send the request to the one obviously free bean instance?
    This happens after several hours and over 100000 incoming requests, and the same scenario worked fine in the old weblogic 8 environment.
    We get the following stacktrace:
    <code>
    "[ACTIVE] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'" waiting for lock java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@b0d484 TIMED_WAITING
    sun.misc.Unsafe.park(Native Method)
    java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:198)
    java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2054)
    weblogic.ejb.container.pool. StatelessSessionPool.waitForBean (StatelessSessionPool.java:269)
    weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSessionPool.java:111)
    weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessManager.java:148)
    weblogic.ejb.container.internal.BaseRemoteObject.preInvoke(BaseRemoteObject.java:227)
    weblogic.ejb.container.internal.StatelessRemoteObject.preInvoke(StatelessRemoteObject.java:52)
    com.mycompany.beans.MessageLogFacace_n73y0z_EOImpl.isMyStuffValid(MessageLogFacace_n73y0z_EOImpl.java:261)
    com.mycompany.beans.MessageLogFacace_n73y0z_EOImpl_WLSkel.invoke(Unknown Source)
    weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
    weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
    weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
    weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
    weblogic.security.service.SecurityManager.runAs(Unknown Source)
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
    weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
    weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
    weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    </code>
    Any help would be very welcome.
    Regards
    Christer

    This is fixed now. Someone had defined a Servlet for the web service in web.xml that was preventing the EJB container to kick in.
    Edited by: user572625 on Aug 25, 2011 11:54 PM

  • Problem in calling single entity bean from other beans

    Hi,
    I am implementing session facade with SUN's J2EE 1.3 deploy tool for JBoss server.
    I have a entity bean UserBean which creates users in database ( create() )and tells if user exists or not ( findByPrimaryKey() ).
    Initially, I had implemented UserBean with remote interfaces. So, any servlet ( my client ) which needed to use UserBean would make a remote call to it. It was used by 5 different servlets.
    Now I am going for Local interfaces. So, I am packaging UserBean with other beans which need it.
    Problem is, if I package UserBean with , say , ChatLogsBean ( Stateless bean ), it works fine. But when I package it with WebLogsBean ( Stateless bean ) also and deploy all beans together, JBoss gives error messages that instances of UserBean are already created.
    How should structure my beans sothat I can avoid these duplication problem ?
    Present flow is as follow:
    Servlet Stateless Bean Other beans
    ChatLogs Servlet --> ChatLogsWrapper --> ChatLogsBean ( Stateless bean ) & UserBean( Entity bean )
    WebLogs servlet --> WebLogsWrapper --> WebLogsBean ( Stateless bean ) & UserBean
    WordLogs servlet --> WordLogsWrapper --> WordLogsBean ( Stateless bean ) & UserBean
    All servlets are packaged into corresponding WARs.
    ChatLogsWrapper , ChatLogsBean ,UserBean are packaged into 'ChatWrapper' JAR.
    WebLogsWrapper , WebLogsBean , UserBean are packaged into 'webWrapper' JAR
    and similarly for WordLogs.
    Any help ?
    Regards,
    Suraj

    I suggest you post to one of the forums on jboss.org. There should not be a problem AFAIK having remote and local interfaces to the same EJB. I assume that you gave these unique names (FooHome/FooLocalHome..etc...) for the home and remote interfaces and declared both in the ejb DD.

  • Creating a bean within another bean and JNDI

    Hello,
    I am trying to have one bean (a session bean) create another bean (entity
    bean). I keep getting a naming exception. Both beans are deployed in the
    same JAR file. Also, I can directly create the entity bean (from a client
    test app).
    Here is the code I have in the session bean:
    try
    Context initial = new InitialContext();
    Object objref = initial.lookup("java:comp/env/ejb/User");
    UserHome userHome =
    UserHome)PortableRemoteObject.narrow( objref, UserHome.class );
    user = userHome.create( username, password );
    catch( NamingException e )
    e.printStackTrace();
    The result is a naming exception, which is shown below. Why does the naming
    exception say "comp.env.ejb.User"?
    ***** Naming Exception *****
    javax.naming.NameNotFoundException: 'comp.env.ejb/User'; remaining name
    'ejb/Use
    r'
    at
    weblogic.jndi.toolkit.BasicWLContext.resolveName(BasicWLContext.java,
    Compiled Code)
    at
    weblogic.jndi.toolkit.BasicWLContext.lookup(BasicWLContext.java:133)
    at
    weblogic.jndi.toolkit.BasicWLContext.lookup(BasicWLContext.java:143)
    at
    weblogic.jndi.toolkit.BasicWLContext.lookup(BasicWLContext.java:143)
    at
    weblogic.jndi.toolkit.BasicWLContext.lookup(BasicWLContext.java:143)
    at
    weblogic.jndi.toolkit.BasicWLContext.lookup(BasicWLContext.java:574)
    at
    weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyCo
    ntextWrapper.java:29)
    at
    weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.j
    ava:117)
    at javax.naming.InitialContext.lookup(InitialContext.java:350)
    at
    com.ecocap.EcoCapSystemBean.authenticate(EcoCapSystemBean.java:51)
    at
    com.ecocap.EcoCapSystemBeanEOImpl.authenticate(EcoCapSystemBeanEOImpl
    .java:146)
    at
    com.ecocap.EcoCapSystemBeanEOImpl_WLSkel.invoke(EcoCapSystemBeanEOImp
    l_WLSkel.java:120)
    at
    weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(BasicServerOb
    jectAdapter.java, Compiled Code)
    at
    weblogic.rmi.extensions.BasicRequestHandler.handleRequest(BasicReques
    tHandler.java:77)
    at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    .java:15)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
    Code)
    Mon Mar 19 17:02:58 EST 2001:<I> <EJB JAR deployment ecocap> Exception in
    non-tr
    ansactional EJB invoke:
    java.lang.Exception: NamingException
    at
    com.ecocap.EcoCapSystemBean.authenticate(EcoCapSystemBean.java:60)
    at
    com.ecocap.EcoCapSystemBeanEOImpl.authenticate(EcoCapSystemBeanEOImpl
    .java:146)
    at
    com.ecocap.EcoCapSystemBeanEOImpl_WLSkel.invoke(EcoCapSystemBeanEOImp
    l_WLSkel.java:120)
    at
    weblogic.rmi.extensions.BasicServerObjectAdapter.invoke(BasicServerOb
    jectAdapter.java, Compiled Code)
    at
    weblogic.rmi.extensions.BasicRequestHandler.handleRequest(BasicReques
    tHandler.java:77)
    at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
    .java:15)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled
    Code)
    Mike

    thanks, but look at the new code i modified still given error on not resolving the class LoginBean in the class LoginDataBean. here is the new code.
    package webclass;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class LoginDataBean
         private Connection cn;
         private PreparedStatement addRecord;
         public LoginDataBean()throws Exception
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              cn = DriverManager.getConnection("jdbc:odbc:portal");
         public void addClient(LoginBean log)throws SQLException
              addRecord.executeUpdate("insert into clientprofile(firstname,middlename,lastname,address,occupation,organisation,gender,email,username,password)values('"+log.getFNfield()+"','"+log.getMDfield()+"','"+log.getLNfield()+"','"+log.getAdresfield()+"','"+log.getOrgfield()+"','"+log.getEmail()+"','"+log.getUsername()+"','"+(String)log.getPasword()+"'");
              addRecord.close();
              cn.close();

  • Injecting a bean in another bean in EJB3?

    Hello all,
    I am trying to inject a bean in another bean, then making a JUnit test for the parent bean. The problem is that it is displaying a nullpointerexception.
    Is the way of injection of a bean in another bean different from injecting a bean in JSF backing bean or any other client?
    I am using glassfish and EJB 3.
    Here is the code.
    JUnit Test
    @Test
        public void testReturnRequestURL() {
            List<String[]> listParameters = new ArrayList<String[]>();
            /* Assigning values for variables */
            ABean instance = new ABean();
            String result = instance.returnString(listParameters);
            System.out.println(result);
    Parent EJB
    @Stateless
    public class AccountsCheckingBean implements AccountsCheckingBeanInterface {
        @EJB
        private BBean bBean;
        public String returnString(List<String[]> listParameters) {
            String strNew = new String();
            strNew = bBean.appendXML("fileName.xml", listParameters); // *returns null here*
            return strNew;
    }What's going wrong here?

    Thanks for your reply. I am using the integrated WLS for this test.
    However, I think it might not be a previous deployment issue. I removed the dependency of ModelEJBOne on ModelEJBTwo and the application loads successfully.
    No new Session Bean was created or modified when the application failed to load. I only added a dependency that ties project ModelEJBOne to project ModelEJBTwo when it failed to load.

  • Difference between a Managed Bean and Backing Bean

    hi
    i am new to JSF made my 1st appl today ...
    couldnt clearly understand difference between a Managed Bean and Backing Bean , anybody know the difference?
    Regards
    dsdsf

    These are two terms that means the same .... A backing bean is a normal web term, in JSF specifically it is termed as managed bean as this' backing bean' configurations in faces-config.xml are termed within 'managed-bean ' tags.
    Cutting the long story short its a bean class . period :)

  • Access a manage bean through other bean/validator

    Hello
    I want to access a session managed bean from a Validator i created.
    I did added that to my faces-config.xml :
         <referenced-bean>
              <referenced-bean-name>userDetails</referenced-bean-name>
              <referenced-bean-class>com.ibm.manageBeans.UserDetails</referenced-bean-class>          
         </referenced-bean>
    but how do i access the bean within the validator class ??
    Thanks

    I found why this happen but i can't fix it :
    It happen because the validator class is invoking
    before the bean's setters are.
    So naturally the validator get a null when he uses
    the getters.
    What should I do in such a case ?Based on what you have written I imagine you are expecting the bean's values to be set from values in the request? If you are just acting on one value, i.e. the thing you are validating then that value is passed into the validator method, you do not need to get it from a bean.

Maybe you are looking for

  • View the anniversaries in iCal

    good morning.  How can I view the anniversaries in ical placed in contact? of course everything is synchronized (iPhone, iPad and iMac) with icloud

  • "Smart" Groups not being recognized when syncing with iPhone

    I have several "smart" groups in my address book but they don't show up as available to sync with my iPhone. What's up with that?

  • Navigation does not work correctly

    I am implementing a table view with navigation. When the first row is selected, it should navigate to a second view with a "back" button in the navigation bar. In my case, when the cell or row is selected in the table, it does not do anything (does n

  • Can't register my computer with icloud

    I just "upgraded" from MobileMe to ICloud. However, I have not been allowed to register my computer. I follow all the prompts and end up with the never ending rotating swirl. Please help me with simple instructions.

  • Album Artwork Chronically Loses Album Artwork

    This has been a problem with my last three iPods (don't know why I keep getting them considering, I suppose it's because everything else works great) and now it is happing with my iPhone. I will have them for months and everything is hunky dory. Then