1 Reply Latest reply on Mar 14, 2006 9:16 AM by pdog4x4

    Problems if i try to access database

    cocofrance

      when i want to set some datas in my database like that :


      public void ajoutePays(String detail_pays) throws Exception{
       System.out.println("Execute CommonSessionBean.ajoutePays");
       int idpays=0;
       String pays = getMaxIdPays();
       if(pays!=null) idpays = Integer.parseInt(pays);
       try {
       PaysLocal paysLocal = paysLocalHome.create(""+idpays+1,detail_pays);
       System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
       System.out.println("CommonSessionBean.ajoutePays : ajout reussi");
       System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
       }catch(Exception ex){
       System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
       System.out.println("Erreur CommonSessionBean.ajoutePays : la pays ==> "+detail_pays+" existe déja");
       System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++");
       throw ex;
       }
       System.out.println("Quitte CommonSessionBean.ajoutePays");
       }


      instead, i get this exception :

      org.jboss.tm.JBossTransactionRolledbackException: null; CausedByException is:
      null; nested exception is:
      java.lang.NullPointerException; - nested throwable: (java.lang.NullPointerException)
      at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:267)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:196)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
      at org.jboss.ejb.Container.invoke(Container.java:709)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:62)
      at org.jboss.mx.server.Invocation.dispatch(Invocation.java:54)
      at org.jboss.mx.server.Invocation.invoke(Invocation.java:82)
      at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:198)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
      at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
      at sun.rmi.transport.Transport$1.run(Transport.java:153)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.lang.NullPointerException
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:572)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:211)
      at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:573)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1066)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:204)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:97)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:317)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:130)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:85)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:121)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
      at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:478)
      at org.jboss.ejb.Container.invoke(Container.java:729)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:347)
      at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
      at $Proxy90.create(Unknown Source)
      at atlantis.m.common.session.CommonSessionBean.ajoutePays(CommonSessionBean.java:226)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:317)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:150)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:111)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
      ... 24 more

      i'm using a CMP bean

      please help!!!

        • 1. Re: Problems if i try to access database
          pdog4x4

          coco,

          Ensure that idpays is setup properly, as a side note I'm not sure it is being assigned the appropriate value.

          PaysLocal paysLocal = paysLocalHome.create(""+idpays+1,detail_pays);
          


          This may or may not be the desired result, this code will append a one to the end of idpays, so 100 becomes 1001. If this is the desired outcome, ignore, otherwise, specify order by using parentesis. See the following example:

          public class test {
           public static void main(String [] args) {
           int idpays = 100;
          
           System.out.println("\"\"+idpays+1 = " + idpays+1);
           System.out.println("\"\"+(idpays+1) = " + (idpays+1));
           }
          }
          


          Oddly enough returns the following:

          ""+idpays+1 = 1001
          ""+(idpays+1) = 101
          


          Also, check the source at:

          atlantis.m.common.session.CommonSessionBean line 226.

          Perhaps there is a check in CommonSessionBean that is kicking it back null? Otherwise, make sure you initializing the local home interface? I usually setup something to the effect of:

           if ( paysLocalHome == null ) {
           // local interface is null, initialize a new context
           try {
           InitialContext ctx = new InitialContext();
           Object objref = ctx.lookup("adjust/to/your/ejb/local/jndi/name/Pays");
           paysLocalHome = (PaysLocalHome) PortableRemoteObject.narrow(objref, PaysLocalHome.class);
           } catch (ClassCastException e) {
           log("ClassCastException occurred, unable to create session bean!",e);
           } catch (NamingException e) {
           log("NamingException occurred, unable to create session bean!",e);
           }
           }
          


          Anyhow, more code would be helpful.

          Thanks!

          Joshua Preston.