1 Reply Latest reply on Apr 26, 2004 12:38 PM by Raja

    javax.ejb.CreateException: Error checking if entity exists

    chaitanyahazari Newbie

      Hi all,

      I'm a beginner to JBoss, could anyone plz help me in resolving this issue...

      I ve written a simple entity bean to insert name and id in a table called DEMO. I ve tried giving some SOPs and what i ve found is that its working fine till the end of ejbCreate and the SOP that i give in ejbPostCreate doesnt come up.

      My classes are :-

      -----------------------BEAN-----------------------

      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import java.rmi.RemoteException;


      public abstract class AddVotesForContestBean implements EntityBean
      {
      protected EntityContext m_context;


      /**
      * set methods
      */
      public abstract void setName(String theName);
      public abstract void setId(int theId);

      /**
      * get methods
      */

      public abstract String getName();
      public abstract int getId();


      /**
      * Called by Container.
      * Implementation can acquire needed resources.
      */

      public void ejbActivate()
      {
      }

      /**
      * Called by Container.
      * Releases held resources for passivation.
      */

      public void ejbPassivate()
      {
      }

      /**
      * Called from the Container.Updates the entity bean instance to reflect
      * the current value stored in the database.
      *
      * The EJB Container will automatically load us in the subclass.
      */

      public void ejbLoad()
      {
      }

      /**
      * Called from the Container.Updates the database to
      * reflect the current values of this in-memory Entity Bean
      * instance representation.
      */

      public void ejbStore()
      {
      }

      /**
      * EJB Container calls this method right before it removes the Entity Bean
      * from the database. Corresponds to when client calls home.remove().
      */

      public void ejbRemove()
      {
      }

      /**
      * Called by Container.Associates this Bean instance with a particular
      * context.Once done,we can query the Context for environment info
      */

      public void setEntityContext(EntityContext theContext)
      {
      if(theContext != null)
      {
      m_context = theContext;
      }
      }

      /**
      * Called by Container.Disassociates this Bean instance
      * with a particular context environment.
      */

      public void unsetEntityContext()
      {
      m_context = null;
      }

      /**
      * This is the initialization method that corresponds to the create() method
      * in the Home Interface.
      * @param theContestDetailsVO
      */


      public Integer ejbCreate(ContestDetailsVO theContestDetailsVO)
      throws CreateException,RemoteException
      {
      try
      {
      setName(theContestDetailsVO.getName());
      setId(theContestDetailsVO.getId());
      }
      catch(Exception e)
      {
      System.out.println("Inside catch of Bean");
      e.printStackTrace();
      }
      return new Integer(this.getId());
      }

      /**
      * Called after ejbCreate(). Now,the Bean can retrieve its EJBObject from
      * its context,and pass it as a 'this' argument.
      */

      public void ejbPostCreate(ContestDetailsVO theContestDetailsVO)
      {
      System.out.println("inside post create");
      }

      }

      -----------------------REMOTE-----------------------


      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;

      public interface AddVotesForContest extends EJBObject {

      public void setName(String theName) throws RemoteException;
      public void setId(int theId) throws RemoteException;

      public String getName() throws RemoteException;
      public int getId() throws RemoteException;

      }

      -----------------------HOME-----------------------

      public interface VotesForContestHome extends EJBHome
      {
      public AddVotesForContest create (ContestDetailsVO aContestDetailsVO)
      throws CreateException, RemoteException;

      public AddVotesForContest findByPrimaryKey (Integer theId)
      throws FinderException, RemoteException;
      }

      When trying to insert the data using a jsp it's giving me the following exception

      16:24:03,277 ERROR [AddVotesForContestBean] Error checking if entity exists
      java.sql.SQLException: Syntax error or access violation: You have an error in your SQL syntax near '' at line 1
      at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
      at com.mysql.jdbc.Connection.execSQL(Unknown Source)
      at com.mysql.jdbc.PreparedStatement.executeQuery(Unknown Source)

      I ve ensured that im not entering a value which is already existing, also the xml files seems to be okay could u plz lemme know where could be potential problem....

      Thanks in advance,

      Chaitanya