MySQLSyntaxErrorException: Table XYZ doesn't exist

If the table really, really, does exist in mySQL, and your using Linux/Unix, and the error shows the table name in wrong/upper-case, then the issue is that table names in MySQL are case sensitive and hibernate is upper casing them. I'm using hibernate 4.3.

I just had this issue. Explanation here: lower_case_table_names=1

--edit-- In retrospect, it's probably better to find and change any @Table or hbm.xml references to match the database. I ran a wizard that generated an hbm.xml with uppercase names -- didn't realize that it was in my project until just now. I'll leave this here to make people aware of the case sensitivity.

--end of edit--

Here is how I fixed it:

  1. Drop the database.
  2. Add this to /etc/mysql/my.conf:

    set lower_case_table_names=1 #(default value '0'). 
    
  3. Restart mysqld.
  4. Recreate the Database.
  5. ( optional? ) change annotation/hbm.xml table references to lower case.

From your entity definition, remove the catalog = 'reportsDb' part, since it is being used to build the query like select from 'reportsDb.alerts'. Mysql doesn't use catalogs, AFAIK.


After exasperadetly eliminating every single occurence of table XYZ in my code, I found the actual issue: XYZ wasn't being referenced by JPA, but by an old, invalid mysql trigger. Maybe consider looking for the error outside of your code.