1 Reply Latest reply on Jan 14, 2003 9:28 AM by bs3511

    Help me

    janarthan77

      HI,

      I am 2 week old to EJB.
      I am using jboss 3.0 as container.
      I am using xdoclet for auto generation of code.
      I have written an EntityBean "AccountBean.java" which reads as -

      package helloworld;

      import java.util.Collection;
      import javax.ejb.SessionBean;
      import javax.ejb.EntityContext;

      /**
      * @ejb.bean type="CMP"
      * jndi-name="helloworld/Account"
      * view-type="both"
      * @ejb.finder signature="Collection findAllAccounts()"
      * @ejb.pk
      * @jboss:table-name "user_profile"
      * @ejb:transaction type="Required"
      *
      */



      public abstract class AccountBean implements javax.ejb.EntityBean {

      /**
      * Create Account.
      *
      * @ejb.create-method
      */
      public Object ejbCreate() throws javax.ejb.CreateException {
      System.out.println("In ejbCreate()");
      return new AccountPK();
      // return null;
      }

      /**
      * Create Account with parameters.
      *
      * @ejb.create-method
      */
      public Object ejbCreate(String vUserIdentity,
      String vFirstName,
      double vPinCode
      ) throws javax.ejb.CreateException {
      System.out.println("In ejbCreate() parametrised");
      setUserIdentity(vUserIdentity);
      setFirstName(vFirstName);
      setPinCode(vPinCode);

      System.out.println("returning AccountPK with acount NO " + vUserIdentity);
      return new AccountPK(vUserIdentity);
      // return null;
      }

      public void ejbPostCreate(String vUserIdentity,
      String vFirstName,
      double vPinCode
      ) throws javax.ejb.CreateException {
      System.out.println("In ejbPostCreate() parametrised");
      }

      public void ejbPostCreate() throws javax.ejb.CreateException {
      System.out.println("In ejbPostCreate()");
      }


      /**
      * @ejb.pk-field
      * @ejb.persistent-field
      * @ejb.interface-method
      * @jboss:column-name user_identity
      */

      public abstract String getUserIdentity();
      public abstract void setUserIdentity(String vUserIdentity);

      /**
      * @ejb.persistent-field
      * @ejb.interface-method
      * @jboss:column-name pin_code
      */
      public abstract double getPinCode();
      public abstract void setPinCode(double vPinCode);

      /**
      * @ejb.persistent-field
      * @ejb.interface-method
      * @jboss:column-name first_name
      */
      public abstract String getFirstName();
      public abstract void setFirstName(String vFirstName);

      /**
      * @ejb.interface-method
      */

      public String accountInfo() {
      return "Your account(change to pincode) has Rs. " + getPinCode() + " as balance";
      }


      }


      Now to test this Entitybean, i wrote a class named "AccountClient.java" which reads as -

      package helloworld;

      import javax.ejb.*;
      import javax.naming.*;
      import java.rmi.*;
      import java.util.Properties;
      import java.util.Vector;

      class AccountClient
      {
      public static void main(String[] args)
      {
      System.out.println("\nBegin AccountClient ..\n");

      try
      {
      // Create an Authentication object, in the server
      Context ctx = new InitialContext();
      System.out.println("context = " + ctx);
      System.out.println("received context - now looking up \n");
      Object obj = ctx.lookup("helloworld/Account");

      AccountHome mAccountHome = (AccountHome) javax.rmi.PortableRemoteObject.narrow(obj, AccountHome.class) ;

      System.out.println("before creating Account\n");
      mAccountHome.create("user_001", "janarthan", 10500);
      //mAccountHome.create("janarthan", 10500);
      // mAccountHome.create();
      System.out.println("after creating Account\n");

      // Here is the call that executes the method on home objects find method
      Vector mResult = (Vector)mAccountHome.findAllAccounts();
      System.out.println("The result is " + mResult);
      }
      catch (Exception e)
      {
      System.out.println(":::::::::::::: Error :::::::::::::::::");
      e.printStackTrace();
      }
      System.out.println("\nEnd Account...\n");
      }

      }


      I compile and deploy the appln.Everthings OK.

      I now run the AccountClient.java.

      I get an exception as -
      [java]
      [java] Begin AccountClient ..
      [java]
      [java] context = javax.naming.InitialContext@888759
      [java] received context - now looking up
      [java]
      [java] before creating Account
      [java]
      [java] :::::::::::::: Error :::::::::::::::::
      [java] javax.ejb.CreateException: Error checking if entity exists:java.sql.SQLEx
      ception: Column not found: USER_IDENTITY in statement [SELECT COUNT(*) FROM USER_P
      ROFILE WHERE user_identity='user_001']
      [java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.entityEx
      ists(JDBCCreateEntityCommand.java:166)
      [java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(
      JDBCCreateEntityCommand.java:127)
      [java] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JD
      BCStoreManager.java:450)
      [java] at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPer
      sistenceManager.java:253)
      [java] at org.jboss.resource.connectionmanager.CachedConnectionIntercepto
      r.createEntity(CachedConnectionInterceptor.java:270)
      [java] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:7
      28)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccesso
      rImpl.java:39)
      [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMetho
      dAccessorImpl.java:25)
      [java] at java.lang.reflect.Method.invoke(Method.java:324)
      [java] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(E
      ntityContainer.java:1116)
      [java] at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractIn
      terceptor.java:73)
      [java] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHo
      me(EntitySynchronizationInterceptor.java:257)
      [java] at org.jboss.resource.connectionmanager.CachedConnectionIntercepto
      r.invokeHome(CachedConnectionInterceptor.java:215)
      [java] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(Enti
      tyInstanceInterceptor.java:134)
      [java] at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLo
      ckInterceptor.java:79)
      [java] at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(Enti
      tyCreationInterceptor.java:44)
      [java] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(Abstract
      TxInterceptor.java:98)
      [java] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIn
      terceptorCMT.java:167)
      [java] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptor
      CMT.java:52)
      [java] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIn
      terceptor.java:104)
      [java] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.
      java:109)
      [java] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:4
      87)
      [java] at org.jboss.ejb.Container.invoke(Container.java:726)
      [java] at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)

      [java] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java
      :491)
      [java] at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker
      .java:362)
      [java] at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source)
      [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMetho
      dAccessorImpl.java:25)
      [java] at java.lang.reflect.Method.invoke(Method.java:324)
      [java] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:
      261)
      [java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
      [java] at java.security.AccessController.doPrivileged(Native Method)
      [java] at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      [java] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.
      java:460)
      [java] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTra
      nsport.java:701)
      [java] at java.lang.Thread.run(Thread.java:536)
      [java] at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(
      StreamRemoteCall.java:247)
      [java] at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall
      .java:223)
      [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
      [java] at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknow
      n Source)
      [java] at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JR
      MPInvokerProxy.java:128)
      [java] at org.jboss.invocation.InvokerInterceptor.invoke(InvokerIntercept
      or.java:108)
      [java] at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterc
      eptor.java:73)
      [java] at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.
      java:76)
      [java]
      [java] at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeIntercep
      tor.java:185)
      [java] End Account...
      [java] at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)

      [java] at $Proxy0.create(Unknown Source)
      [java]
      [java] at helloworld.AccountClient.main(Unknown Source)



      Please help me get out of this. I have not figured why this exception comes. The table that i am referring does contain 'USER_IDENTITY' as its field.

      I have fought this for 2 days. Please help me !!!

        • 1. Re: Help me
          bs3511

          Perhaps you have not corrctly edited ejb-jar.xml file, there you have to explicitly specify EJB version.

          Better look at the examples folder or read the EntityBean from the theserverside.com EJB Book by Ed. Roman

          I hope this will work !

          USER_IDENTITY is field from entity bean.