Why does Hibernate query have compile error in IntelliJ?
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.
In IntelliJ IDEA 13 for Mac OS X I could find this option as "Query Language Checks" under "JPA Issues"
Make sure that you have your Facets configured correctly. I was getting errors in my Spring Data JPA @Query annotations of "Can't resolve symbol" (just within IntelliJ IDEA; the code itself worked fine when I ran it) and I needed to go into Project Structure, Facets and add the JPA facet. (I assume if one is using Hibernate without JPA, then one would just add the Hibernate facet rather than the JPA facet.)
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.