我使用 Java 配置在 Spring 中配置了 JPA/Hibernate,没有任何 persistence.xml
文件,使用 EntityManagerFactory
的 packagesToScan
属性:
@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 - IntelliJ : How to enable JPAQL validation without persistence. XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297430/