4 Replies Latest reply on Jun 11, 2004 9:40 AM by Alexey Loubyansky

    Error checking if entity exists

    Alexandre Touret Newbie

      Hi all,
      I trying to use CMP EJB with JBOSS 3.2.3 and MS SQL Server 2000.

      When I am trying to create a simple EJB I have the following error:

      2004-06-09 15:44:25,613 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Customer] Error checking if entity exists
      java.sql.SQLException: Unexpected token: in statement [SELECT COUNT(*) FROM CUSTOMER WHERE ]
      at org.hsqldb.Trace.getError(Unknown Source)
      at org.hsqldb.jdbcResultSet.(Unknown Source)
      at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
      at org.hsqldb.jdbcConnection.execute(Unknown Source)
      at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
      at org.hsqldb.jdbcStatement.executeQuery(Unknown Source)
      at org.hsqldb.jdbcPreparedStatement.executeQuery(Unknown Source)
      at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:304)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCInsertPKCreateCommand.beforeInsert(JDBCInsertPKCreateCommand.java:83)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:137)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:554)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:208)

      I looked for this error over Internet and this forum, and I didn t found any solution. I m also using Xdoclet with Maven

      My EJB with Xdoclet TAGS

      /**
      * @ejb.bean
      * name="Customer"
      * jndi-name="Customer"
      * local-jndi-name="local/Customer"
      * view-type="local"
      * type="CMP"
      * cmp-version="2.x"
      * @ejb.value-object
      * name="Customer"
      * match="custom"
      * implements="fr.cella.training.directory.Customer"
      * @ejb.persistence table-name="customer"
      * @jboss.create-table "false"
      * @jboss.remove-table "false"
      * @jboss.tuned-updates "true"
      * @ejb.transaction type="Required"
      * @ejb.pk class="java.lang.Integer" generate="false"
      * @jboss.unknown-pk class="java.lang.Integer"
      * column-name="customer_id"
      * jdbc-type="INTEGER"
      * sql-type="int"
      * autoincrement=true"
      * @jboss.entity-command name="mssql-fetch-key"
      * @author atouret
      */
      public abstract class CustomerBean implements EntityBean {
      private static Logger trace= Logger.getLogger(CustomerBean.class);
      private EntityContext entityContext= null;
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#ejbActivate()
      */
      public void ejbActivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#ejbLoad()
      */
      public void ejbLoad() throws EJBException, RemoteException {
      // TODO Auto-generated method stub
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#ejbPassivate()
      */
      public void ejbPassivate() throws EJBException, RemoteException {
      // TODO Auto-generated method stub
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#ejbRemove()
      */
      public void ejbRemove() throws RemoveException, EJBException, RemoteException {
      // TODO Auto-generated method stub
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#ejbStore()
      */
      public void ejbStore() throws EJBException, RemoteException {
      // TODO Auto-generated method stub
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
      */
      public void setEntityContext(EntityContext context) throws EJBException, RemoteException {
      entityContext= context;
      }
      /* (non-Javadoc)
      * @see javax.ejb.EntityBean#unsetEntityContext()
      */
      public void unsetEntityContext() throws EJBException, RemoteException {
      setEntityContext(null);
      }
      /**
      * @return
      */
      private EntityContext getEntityContext() {
      return entityContext;
      }

      /**
      * @ejb.value-object match="custom"
      * @ejb.persistence column-name="address"
      * @ejb.interface-method
      *
      * @return
      */
      public abstract String getAddress();
      /**
      * @ejb.value-object match="custom"
      * @ejb.persistence column-name="city"
      * @ejb.interface-method
      * @return
      */
      public abstract String getCity();
      /**
      * @ejb.value-object match="custom"
      * @ejb.persistence column-name="firstname"
      * @ejb.interface-method
      * * @return
      */
      public abstract String getFirstname();
      /**
      * @ejb.persistence column-name="surname"
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * @return
      */
      public abstract String getSurname();
      /**
      * @ejb.persistence column-name="zip"
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * * @return
      */
      public abstract String getZip();
      /**
      * @param string
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      */
      public abstract void setAddress(String string);
      /**
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * @param string
      */
      public abstract void setCity(String string);
      /**
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * @param string
      */
      public abstract void setFirstname(String string);
      /**
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * @param string
      */
      public abstract void setSurname(String string);
      /**
      *
      * @ejb.value-object match="custom"
      * @ejb.interface-method
      * @param string
      */
      public abstract void setZip(String string);
      /**
      * @ejb.create-method
      * @return
      * @throws CreateException
      */
      public Object ejbCreate() throws CreateException {
      return null;
      }
      public void ejbPostCreate() throws CreateException {
      }
      /**
      * @ejb.create-method
      * @return
      * @throws CreateException
      */
      public Object ejbCreate(Customer customer) throws CreateException {
      setFirstname(customer.getFirstname());
      setSurname(customer.getSurname());
      setAddress(customer.getAddress());
      setZip(customer.getZip());
      setCity(customer.getZip());

      return null;
      }
      public void ejbPostCreate(Customer customer) throws CreateException {
      }
      /**
      * @ejb:interface-method
      * @return
      */
      public Customer getValue() {
      CustomerValue value= new CustomerValue(getAddress(), getCity(), getFirstname(), getSurname(), getZip());
      value.setPrimaryKey((Integer) getEntityContext().getPrimaryKey());
      return value;
      }
      }



      Thanks for helping

      Alexandre Touret