2

I am connecting to a MySQL table using JPA Hibernate. But I am getting error in my Java code:

org.hibernate.HibernateException: Missing table 

My table is present in MySQL database schema. I am not getting why missing table exception is thrown here. This is a newly created table. All other existing tables in the same schema are accessible from Hibernate. I saw similar posts with same error. But the answers there didn't help my cause. Can you please let me know what can be the issue here.

2 Answers 2

1

If table is present, then most likely it is user permission issue. This happens if you have created the table using a different MySQL user. Make sure the MySQL username/password that you are using in Hibernate is having access to the table. To test, login to MySQL console directly using Hibernate credential & run a select query on the table. If you see similar error as below, then you need to grant access to the table for the Hibernate user.

ERROR 1142 (42000): SELECT command denied to user

Source: http://www.w3spot.com/2020/10/how-to-solve-caused-by-hibernateexception-missing-table.html

Sign up to request clarification or add additional context in comments.

1 Comment

This was the problem. Thank you very much!
1
  • Make sure the user has access to the table
  • Make sure names are equals in terms of case sensitivity
  • Make sure the schema name and table name are not misspelled

If you share more information about the issue, it would be easier to pinpoint the problem.
Chances are there is an inheritance scenario with a physical table that you assumed to be abstract.

To dig deeper you can put a breakpoint in org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl#getTablesInformation which calls extractor.getTable to see why your table is not returned as part of schema tables. Rerun the app with the specified breakpoint and step through lines to get to the line which queries table names from the database metadat.

    @Override
    public TableInformation getTableInformation(QualifiedTableName tableName) {
        if ( tableName.getObjectName() == null ) {
            throw new IllegalArgumentException( "Passed table name cannot be null" );
        }

        return extractor.getTable(
                tableName.getCatalogName(),
                tableName.getSchemaName(),
                tableName.getTableName()
        );
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.