IntelliJ:如何在没有 persistence.xml 的情况下启用 JPAQL 验证?
IntelliJ : How to enable JPAQL validation without persistence.xml?
我使用 Java 配置在 Spring 中配置了 JPA/Hibernate,没有任何 persistence.xml
文件,使用 packagesToScan
属性 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;
}
但现在 IntelliJ IDEA 不再理解它了,我在 JPAQL 查询中的实体被标记为红色并显示以下消息,并且自动完成不起作用:
Can't resolve symbol 'MyEntityName'
是否可以配置 IntelliJ,以便它也扫描给定包的 JPA @Entity
?
嗯,原来是我在 IntelliJ 项目中没有正确配置Spring。
在向模块添加 Spring 方面并映射我的两个 @Configuration
注释 类 之后,IntelliJ 再次完美地识别了我的 JPAQL 查询中的实体。
我使用 Java 配置在 Spring 中配置了 JPA/Hibernate,没有任何 persistence.xml
文件,使用 packagesToScan
属性 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;
}
但现在 IntelliJ IDEA 不再理解它了,我在 JPAQL 查询中的实体被标记为红色并显示以下消息,并且自动完成不起作用:
Can't resolve symbol 'MyEntityName'
是否可以配置 IntelliJ,以便它也扫描给定包的 JPA @Entity
?
嗯,原来是我在 IntelliJ 项目中没有正确配置Spring。
在向模块添加 Spring 方面并映射我的两个 @Configuration
注释 类 之后,IntelliJ 再次完美地识别了我的 JPAQL 查询中的实体。