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??
Create a new Java Enterprise project with HibernateClick New Project on the Welcome screen or select File | New | Project. From the Generators list, select Jakarta EE. Name the new project, select a build tool, a language you want to use, and select the Web application project template.
Right click on the desired module -> Add -> Hibernate. Select the newly created Hibernate configuration option, and click the (+) sign in the right pane to create hibernate. cfg. xml file.
Add a "Hibernate" Facet under "Project Structure", then for that Facet select the "hibernate.cfg.xml" file for "Hibernate Configuration". This will let IDEA know about your class to table mapping and will help it recognize those classes in HQL queries.
If you don't use "hibernate.cfg.xml", for example for Spring you may just use "applicationContext.xml" to initialize your datasource, having Hibernate Facet declared may be enough.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With