Hibernate error: cannot resolve table

Your IDE is telling you it can't find the table. You can change it to just a warning in IDEA so that your project will atleast compile.


To validate a hbm.xml file mappings, just do the following (Intellij Ultimate 2017.1):

View -> Tool Windows -> Database -> click (+) sign -> Data Source -> MySQL

You've added a datasource for your database's server. Now you should create the datasource. The next step is adding this datasource to hibernate mappings. Just follow me:

View -> Tool Windows -> Persistence

The Persistence window will be opened. You must see the project listed.

Right click on the project -> Assign Data Sources...

In the opened window, there should be 2 columns: "Session Factory" and "Data Source". Just add defined datasource above in the second column.


We need substantially more information to help you out.

Is this a command line application? What runtime error is given? What IDE are you using? What is the output from enabling hibernate's debug logging?


This has nothing to do with Hibernate, this is an IDEA "issue" and you need to configure it properly for tables names validation in hbm.xml. From this old thread:

In order for IntelliJ to provide proper code completion and validation for database tables/columns, it needs to know about the database structure of your application as well. So, I'm referring to the IntelliJ datasource. Think of it as a "development-time datasource", or something like that.

To create one:
Window -> Tool Windows -> Data sources
Add ("plus" icon) -> JDBC data source

As an alternative, you could try the "Import" button in the "Date sources" tool window. This makes IntelliJ search your project for some specific configuration files (like "hibernate.cfg.xml"), from which it can directly import a datasource definition.

However, if that fails, you can always define a JDBC data source manually (jdbc url, driver jar, driver class, etc).

Once you have a datasource configured, test it by opening an SQL console on it ("console" button in datasource tool window), and type some queries. IDEA should provide SQL code completion here, for table and column names.

If this step works, go to the definition of the datasource, and invoke

"Refresh Tables". This makes IntelliJ retrieve the database structure.

Next, open "Project Structure" (Ctrl-Shift-Alt-S). Select your Hibernate facet (though either "Facets" or "Modules").

The options screen for the Hibernate facet has a pane named "DataSources Mapping". Here you can associate your Hiberante session factory with a specific IntelliJ datasource.

After this step, SQL table/column code completion and validation should work in .hbm files as well.

Applies to IDEA 7 also, read the whole thread if necessary.