Search code examples
javahibernateintellij-idea

Why does Hibernate query have compile error in IntelliJ?


I have this Hibernate code:

Query q = session.createQuery("from MyTable where status = :status");

It compiles and works fine..

But in IntelliJ I get this error reported:

Can't resolve expression, Can't resolve symbol 'MyTable'

Why is IntelliJ complaining??


Solution

  • IntelliJ is trying to validate your HQL query inside the string itself. To do this, it needs to be configured to know about your hibernate configuration to ensure that a mapping exists for MyTable (it does at runtime, as you know - as it executes!).

    Check out the hibernate config section in IntelliJ for your project.

    There is probably a way of turning it off if it is more hindrance than help.