5 Replies Latest reply on Jan 12, 2004 8:06 AM by Klaus Kaal

    No such Entity!

    Klaus Kaal Newbie

      Hi, after having manged session-beans, I am feeling like a newbie again!

      I am trying to create an CMP bean. When I lookup the home-interface, it is allright. But when I try the "findByPrimaryKey method, it throws an ObjectNotFoundException: Not such entity!

      A suitable table exists in the DB.

      could you plse have a look at the code?

      Thanks
      Klaus

      -------------------- 8< Client -code --------------------------------------------
      public String getEnvString() {
      EnvVars ev = null;
      Collection cev = null;
      try {
      Object ref = jndiContext.lookup("sys/env_variables");
      EnvVarsHome evh = (EnvVarsHome) javax.rmi.PortableRemoteObject.narrow(ref, EnvVarsHome.class);
      ev = evh.findByPrimaryKey(new Integer(1)); //this throws the exception!
      return "TEST2";
      }
      catch (RemoteException e2) {
      e2.printStackTrace();
      }
      catch (FinderException e2) {
      e2.printStackTrace();
      }
      catch (ClassCastException e) {
      e.printStackTrace();
      }
      catch (NamingException e) {
      e.printStackTrace();
      }
      try {
      return ev.getName();
      }
      catch (RemoteException e1) {
      e1.printStackTrace();
      return "ERR";
      }
      }

      -------------------------------------------------------------------------------

      ---------------- 8< CMP Bean --------------------------------------------

      /**
      * @ejb.bean cmp-version = "2.x"
      * type = "CMP"
      * view-type = "both"
      * name = "EnvVars"
      * description = "Handles system data"
      * jndi-name = "sys/env_variables"
      * local-jndi-name = "sys/env_variables_local"
      * display-name = "Environment"
      * primkey-field = "id"
      * schema="envi"
      *
      * @ejb.persistence
      * table-name="environment"
      *
      * @ejb.pk class = "java.lang.Integer"
      *
      *
      * @ejb.finder
      * signature = "EnvVars findByPrimaryKey(java.lang.Integer id)"
      * unchecked = "true"
      * query = "SELECT OBJECT(a) from envi a where a.id = 1"
      * result-type-mapping="Local"
      *
      * @jboss.entity-command
      * name="mysql-get-generated-keys"
      * @jboss.persistence
      * datasource="MySqlPublDS"
      * table-name="environment"
      * datasource-mapping = "mySQL"
      * create-table = "true"
      *
      */

      public abstract class EnvVarsBean implements EntityBean {

      Integer id;
      String name;

      public EnvVarsBean() {
      super();
      }

      /**
      * @ejb.create-method
      */
      public Integer ejbCreate( String nam ) throws CreateException{
      this.setName( nam );
      return null;
      }

      public void ejbActivate() throws EJBException, RemoteException {}

      public void ejbLoad() throws EJBException, RemoteException {}

      public void ejbPassivate() throws EJBException, RemoteException {}

      public void ejbRemove() throws RemoveException, EJBException, RemoteException {}

      public void ejbStore() throws EJBException, RemoteException {}

      public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}

      public void unsetEntityContext() throws EJBException, RemoteException {}

      /**
      * @ejb.interface-method
      * @ejb.persistence column-name="id"
      * @ejb.pk-field
      *
      * @jboss.column-name name="id"
      * @jboss.persistence auto-increment="true"
      */
      public abstract Integer getId();

      /**
      *@ejb.interface-method
      */
      public abstract void setId(Integer i);

      /**
      *@ejb.interface-method
      */
      public abstract String getName();

      /**
      *@ejb.interface-method
      */
      public abstract void setName( String nam );


      }
      ------------------------------------------------------------------------------------

        • 1. Re: No such Entity!
          cluck Newbie

          I suggest you turn on your debugger/add appropriate logging to check it is lookup for what you believe it it. And its not really the bean classes that are the important bit with CMP (they are abstract after all) - its the associated xml mapping.

          • 2. Re: No such Entity!
            Darran Lofthouse Master

            You say a suitable table exists in the database. Does it contain a entry with the primary key that you are looking for?

            • 3. Re: No such Entity!
              Klaus Kaal Newbie

              Thanks, Cluck,
              thats exactly where I am stuck. It is not code, it is configuration. How can I trace that with the debugger?? Thats the reason, why I ask the gurus to look over my code and config...

              As I marked it:
              - I can create the home - interface
              - It throws Exception when I try to do the findbyPrimaryKey function

              It states: No such Entity! I have no idea what that means.

              Thanks for further helps.

              Klaus

              • 4. Re: No such Entity!
                Klaus Kaal Newbie

                Darran,

                yes, I made sure (as I first try to just read something) that the table is there, with the right fields and filled with data.

                Thanks for your try.

                Klaus

                • 5. QL
                  Klaus Kaal Newbie

                  Found the problem:

                  Obviously, I had a foulty entry into the tabel with the max-number of Integer. Thus the SQL-entry with id=0 did not create an auto-incremented number (the number was alread at its limit)

                  I created a new table - and it works.

                  Thanks for your thougts

                  Klaus