java - Intellij 如何使用 spring boot 正确配置 hql。现在我得到 Persistence QL Queries are error-checked

标签 java spring hibernate jpa intellij-idea

所以我尝试使用 hibernate 和 jpa 进行自定义查询

@Transactional
public interface EstimateOptionsDao extends JpaRepository<EstimateOptions, Integer> {

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

}

但是 EstimateOptions 给我以下错误:

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

所以我找到了这篇文章 Why does Hibernate query have compile error in IntelliJ? .

所以我添加了一个方面来测试这个:

现在我有这样的 hibernate.cfg.xml:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <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="hbm2ddl.auto">update</property> -->
  </session-factory>
</hibernate-configuration>

像这样的 Spring 配置:

spring.datasource.url=jdbc:mysql://localhost:3306/testdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

但是如果我在 intellij 中使用 Persistence Tool en 做一个像这样的简单查询:

hql> 来自用户

它产生以下错误:

[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: 
.....

如您所见,我有点迷茫...这些设置有什么问题?

最佳答案

  1. Project structure 设置中 (ctrl+alt+shift+s),选择 FacetsAdd
  2. 选择JPA
  3. 选择包含您的映射/注释实体的模块
  4. Modules View 中,选择有问题的模块和下面的 JPA facet
  5. 添加对您的描述符的引用 (persistence.xml/orm.xml)
  6. 从下拉列表中选择您的 JPA 提供商

然后应针对您的实体验证您的 JPA 查询。

关于java - Intellij 如何使用 spring boot 正确配置 hql。现在我得到 Persistence QL Queries are error-checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34178331/

相关文章:

java - JDBC 连接池中的 JDBC 驱动程序加载问题

java - 在 Google Web Toolkit 中使用自定义字体

java - 如何在 Hibernate - Criteria Queries 中获得大于记录?

java - RequestContextHolder.getRequestAttributes() null - Spring Security + Multi-Tenancy

java.lang.StringIndexOutOfBoundsException : String index out of range: 1 异常

java - 在 Java 中复制 Unix 排序的默认行为

java - Spring 核心 3.2.2 + Spring 安全 3.1.4 : java. lang.IncompatibleClassChangeError : org. springframework.asm.ClassVisitor

java - 在 Spring 集成测试中模拟 RestTemplateBuilder 和 RestTemplate

spring - 如果在运行 spring boot 应用程序时不存在 Postgres 数据库,则创建它

java - Hibernate Search (Lucene) 近实时索引管理器和 Tomcat 并行部署