CMP entity bean + JBoss + MySQL = error! Help!

Discussions

EJB programming & troubleshooting: CMP entity bean + JBoss + MySQL = error! Help!

  1. Hi all,

    I'm at my wit's end here. I'm trying to deploy my first CMP entity bean using JBoss and MySQL and I keep getting this error message when deploying the EJB jar:

    <code>
    Caused by: java.sql.SQLException: Syntax error or access violation, message fro
    m server: "You have an error in your SQL syntax. Check the manual that correspo
    nds to your MySQL server version for the right syntax to use near 'User (uid INT
    EGER NOT NULL, fullname VARCHAR(250) BINARY NOT NU"
    </code>

    The definition for my CMP bean looks like (from jbosscmp-jdbc.xml):

    <code>
      <entity>
        <ejb-name>User</ejb-name>
        <table-name>User</table-name>

        <cmp-field>
          <field-name>uid</field-name>
          <column-name>uid</column-name>
          <not-null/>
        </cmp-field>

        <cmp-field>
          <field-name>fullname</field-name> <column-name>fullname</column-name>
          <not-null/>
        </cmp-field>

        <cmp-field>
          <field-name>username</field-name>
          <column-name>username</column-name> <not-null/>
        </cmp-field>

        <cmp-field>
          <field-name>password</field-name>
          <column-name>password</column-name>
          <not-null/>
        </cmp-field>

    </entity>

    </code>

    Any idea what I'm doing wrong to make the SQL get messed up?
  2. As long as I can see there's nothing bad with your deployment descriptor, maybe you should look into your DataSources definitions.
  3. As long as I can see there's nothing bad with your deployment descriptor, maybe you should look into your DataSources definitions.
    Hi Yoandy,

    Thanks for your reply. I don't see how it could be my DataSource definition since it is talking to the MySQL server successfully. I will try to log the SQL statements so I can see the SQL the CMP is trying to execute, maybe we can see it more clearly then.

    Thanks,

    Joe
  4. I have a similar problem, since I get a meaningless message from JBOSS (a syntax error near ) on the query) during the creation of table, can you explain how you log the query made by JBOSS on mysql.

    thanks
  5. I'm not sure how to do this in JBoss, but you can turn on logging in MySQL when you start the server: mysqld_safe --log. All statements will be logged to a file in the data directory.
  6. Problem solved![ Go to top ]

    For anyone who was interested, I found the problem. Actually there were two problems.

    1) The name of the table I assigned to the CMP bean was 'user'. Apparently MySQL doesn't like that since it maintains a 'user' table in the 'mysql' database.

    2) In my primary key class (I always make custom primary key classes even if the primary key is just a primitive type), the variable name of the field did not match the field name I specified in the jbosscmp-jdbc.xml file, so when it was creating the primary key constraint it wasn't passing any field name, so one of the parameters was blank. I fixed that and now my bean deployed no problem!

    Joe