1 Reply Latest reply on Apr 12, 2004 3:57 PM by Gilberto Hernandez

    Error in Generated CMP Existence Check Query

    hqic Newbie

      This is a comment, rather than a question.... I post this because I had a hard time tracking this down, and perhaps this might be of value to someone else in the future.

      I was getting a JBoss error when I'd try to create an entity bean (CMP) and the error was not especially helpful. The interesting thing is that JBoss was generating and invalid query.

      Here's the story...

      I am using JBoss (3.2.1) on MySql (4.0). I have an entity bean that has four attributes; an Integer (primary key) and three Strings. When I'd try to create and instance of the Entity, I'd get the following error in JBoss:


      14:00:07,065 ERROR [CustomerBean] Error checking if entity exists
      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 '' at line 1"
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1626)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:886)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:945)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:1844)
      ...

      I turned on MySql debugging and learned that the statement that JBoss is trying to execute was:

      SELECT COUNT(*) FROM CUSTOMER WHERE

      The incomplete WHERE clause is obviously incorrect. However, the message did clue me into the fact that some attribute was missing. I did an audit of all my attributes, across the implementation bean and deploymnet descriptors and finally realized that I was not supplying the <primkey-field> attribute in ejb-jar.xml (although I did have the <prim-key-class> attribute properly set, and had specified the findByPrimaryKey method on the localhome interface).

      This was resulting in the incorrect sql query and the crypting message about invalid sql.

      It's a bit surprising that JBoss allowed the deployment of the entity bean without complaint even-though the primary key was only partially specified.

      Mike.