Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ : How to enable JPAQL validation without persistence.xml?

I configured JPA/Hibernate in Spring using Java config and without any persistence.xml file, using the packagesToScan property of the EntityManagerFactory :

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
    emf.setDataSource(dataSource());
    emf.setPackagesToScan(new String[]{"ch.gbif.swissBiodivPortal.model.entities"});

    JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    emf.setJpaVendorAdapter(vendorAdapter);
    emf.setJpaProperties(hibernateConfigProperties());

    return emf;
}

But now IntelliJ IDEA does not understand it any more, and my entities in JPAQL queries are marked in red with the following message, and auto-completion does not work :

Can't resolve symbol 'MyEntityName'

Is it possible to configure IntelliJ so it also scans a given package for JPA @Entity ?

like image 616
Pierre Henry Avatar asked Oct 31 '22 00:10

Pierre Henry


1 Answers

Well, it turns out I had not properly configured Spring in the IntelliJ project.

After adding a Spring facet to the module and mapping my two @Configuration annotated classes, IntelliJ perfectly recognizes the entities in my JPAQL queries again.

like image 111
Pierre Henry Avatar answered Nov 15 '22 05:11

Pierre Henry