EJB design: NullPointer Exception

  1. NullPointer Exception (6 messages)

       I am getting NullPointer Exception, when i invoke UserTransaction from Stateless SessionBean in the line UserTransaction ut= ejbContext.getUserTransaction();
    I have tried to use lookup for JNDI also as lookup(java:comp/env/UserTransaction)
    and this shows NameNotFound Exception:UserTransaction Not Bound Error.

    Thanks in Advance
  2. NullPointer Exception[ Go to top ]

    Hi Priya,

    Whats the transaction attribute set in deployment descriptor ?

    If it is "container" then UT will be null all the time.

  3. Hi,
     Thanks for the response. Actually, I am using CMP for the same and the attribute specified in the descriptor is "Required". I am presently trying the deployment in JBOSS 4.0.1SP1. I am actually invoking the UserTransaction in the stateless Session bean using the EJBContext. I got the same exception(NULL Pointer). Now if I change the same to SessionContext, I was getting "CMT not allowed to get into UserTransaction". I have never used the same with JBOSS. I have not registered any JNDI for UserTransaction as we do it for weblogic. Please do specify so as to how to go about. I have seen the console(jmx-console) yesterday and found the user transaction manager entry also which is running.
    If I change the code to the below stated one it will give "Name Not Found Exception- user transaction not bound"

    The Code fragment
    Context ic = new InitialContext();
    String userTxURL = "java:comp/env/UserTransaction";
    UserTransaction ut = (UserTransaction) ic.lookup(userTxURL);

    How to go about with userTransaction with CMP.
  4. Hi Priya,

    As you said you are using CMP, then I wish to know why do you need UT ?


    Trans = Container -- No UT is available, Container manages evrything. To rollback use setRollbackOnly() method on ejb context.

    Trans = Bean --> UT is available and MUST be obtained from ejb context object by calling getUserTransaction().

    Did I answer your que ?

  5. Hi,

    Thanks for Response.I got it.Now i am trying for BMP,In this case also i am getting the same error when i invoke UT with ejbcontext object.I am invoking this from stateless session Bean.I think,i may missed out something in UT.could u pls tell me abt it.
  6. Hi
       I have corrected it.Thanks.
  7. Hi[ Go to top ]

    container manage or bean manage?
    if container manage of course you will get a error.And you used CMP? Why UT additional?