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