Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

java - 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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...