1 Reply Latest reply on Jun 9, 2006 8:59 PM by Lance Drake

    Simple Entity Bean - Help to complete

    jklanka Newbie

      I have setup JBoss-IDE with Eclipse with Jboss. The Jboss Version I use jboss-4.0.2RC1.

      1. I have configured MySQL version 5.0.21 to Jboss. and I followed the URL
      http://www.cotsec.com/documentation/installation/j2ee_jboss_mysql/index.html#3.%20Add%20the%20Java%20MySQL%20Library
      to configure the database with JBoss.


      2. I made a small table with MySQL

      CREATE TABLE `fortunedb`.`test` (
      `id` varchar(10) NOT NULL,
      `name` varchar(45) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


      3. I made a simple Entity Bean Call Test bean to connect to the test table as follow

      ejb-jar.xml::::

      <![CDATA[Description for Test]]>
      <display-name>Name for Test</display-name>

      <ejb-name>Test</ejb-name>

      com.account.TestHome
      com.account.Test

      <ejb-class>com.account.TestCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False

      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Test</abstract-schema-name>
      <cmp-field >
      <![CDATA[]]>
      <field-name>id</field-name>
      </cmp-field>
      <cmp-field >
      <![CDATA[]]>
      <field-name>name</field-name>
      </cmp-field>
      jboss.xml::::::

      <ejb-name>Test</ejb-name>
      <jndi-name>ejb/Test</jndi-name>



      jbosscmp-jdbc.xml::::


      java:/MySqlDS
      <datasource-mapping>mySQL</datasource-mapping>


      <enterprise-beans>

      <ejb-name>Test</ejb-name>
      <table-name>test</table-name>

      <cmp-field>
      <field-name>id</field-name>
      <column-name>id</column-name>

      </cmp-field>
      <cmp-field>
      <field-name>name</field-name>
      <column-name>name</column-name>
      </cmp-field>

      </enterprise-beans>


      4. I am running a Servlet Client to get the connection

      public void init(ServletConfig config) throws ServletException {
      try {
      Context context = new InitialContext();
      Object ref = context.lookup("java:comp/env/ejb/Test");
      home = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);
      } catch (Exception e) {
      throw new ServletException("Lookup of java:/comp/env/ failed" + e);
      }
      }

      protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException,
      IOException {

      resp.setContentType("text/html");
      PrintWriter out=resp.getWriter();


      try {

      Test bean = home.findByPrimaryKey("jk");
      out.print(bean.getName());
      } catch (Exception e) {
      out.print(e);
      }


      5. But when I run this Servlet it gives me the following error

      "javax.ejb.FinderException: Find failed: java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM test t0_Test WHERE' at line 1""

      Please help me to go further on this. I am totally stuck here and I coukld not realise where I made the mistake.

        • 1. Re: Simple Entity Bean - Help to complete
          Lance Drake Newbie

          Hi!

          The SAME problem has defied solution in my project, as well.

          So... what is the root cause for this complaint, pray tell?

          Really, what I'd like to know is "What are the requirements in the jboss XML files that would allow for a successful connection and access to a MySQL database?" I've seen the Connection/J docs - I've queried this site and others - they all offer a smattering of detail - but never get down to the statement, "You MUST - at LEAST - do this - or the game will not start".

          Any vectors to a good JBoss/MySQL sample project I can learn from?

          THANK YOU!