Greg Greg - 1 year ago 215
Java Question

Intellij how to correctly configure hql with spring boot. Now i get Persistence QL Queries are error-checked

So i was trying to use a custom query using hibernate and jpa

public interface EstimateOptionsDao extends JpaRepository<EstimateOptions, Integer> {

@Query("from estimateOptions options inner join company inner join company.user user where = :userName\n")
EstimateOptions EstimateOptions(String userName);


But the
gives me the following error:

Can't resolve symbol 'EstimateOptions' less... (Ctrl+F1)
This inspection controls whether the Persistence QL Queries are error-checked

So i found this post Why does Hibernate query have compile error in IntelliJ?.

So i added a facet to test this:

Now i have hibernate.cfg.xml like this:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
<property name="connection.url"/>
<property name="connection.driver_class"/>
<property name="connection.username"/>
<property name="connection.password"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="">update</property> -->

And spring configuration like this :

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

But if i got to the Persistence Tool in intellij en do a simple query like this:

hql> From user

it produce the following error:

[2015-12-09 12:59:27] org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class []
[2015-12-09 12:59:27] java.lang.ClassNotFoundException:

As you can see i'm a bit lost... What is wrong with these settings ?

Answer Source
  1. In Project structure settings (ctrl+alt+shift+s), select Facets and Add.
  2. Select JPA
  3. Select the module containing your mappings/annotated entities
  4. In the Modules view, select the module in question and the JPA facet underneath
  5. Add a reference to your descriptor (persistence.xml/orm.xml)
  6. Select your JPA provider from the dropdown

Your JPA-queries should then be validated against your entites.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download