Intellij如何使用spring引导正确配置hql。现在我得到了持久性QL查询的错误检查 [英] Intellij how to correctly configure hql with spring boot. Now i get Persistence QL Queries are error-checked
问题描述
所以我试图使用一个使用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\\\
)
EstimateOptions EstimateOptions(String userName) ;
$ b $ EstimateOptions
给了我以下错误:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' )
这个检查控制着持久性QL查询是否被错误检查
所以我发现这个发布为什么Hibernate查询在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/>
<! - 数据库架构将根据需要进行更新 - >
<! - < property name =hbm2ddl.auto>更新< / property> - >
< / session-factory>
< / hibernate-configuration>
以及像这样的弹簧配置:
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,这:
hql>从用户
产生以下错误:
[2015-12-09 12:59:27] org.hibernate.boot.registry.classloading.spi.ClassLoadingException:无法加载类[]
[2015-12-09 12:59:27] java.lang.ClassNotFoundException:
.....
正如你所看到的,我有点失落......这些设置出了什么问题?
项目结构
设置(ctrl + alt + shift + s)中,选择 Facets
和 Add
。 JPA
Modules
视图中,选择您的JPA查询应该根据您的实体进行验证。
So i was trying to use a custom query using hibernate and 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);
}
But the EstimateOptions
gives me the following error:
Can't resolve symbol 'EstimateOptions' less... (Ctrl+F1)
This inspection controls whether the Persistence QL Queries are error-checked
So i found this post Why does Hibernate query have compile error in IntelliJ?.
So i added a facet to test this:
Now i have hibernate.cfg.xml like this:
<?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>
And spring configuration like this :
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
But if i got to the Persistence Tool in intellij en do a simple query like this:
hql> From user
it produce the following error:
[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:
.....
As you can see i'm a bit lost... What is wrong with these settings ?
- In
Project structure
settings (ctrl+alt+shift+s), selectFacets
andAdd
. - Select
JPA
- Select the module containing your mappings/annotated entities
- In the
Modules
view, select the module in question and theJPA
facet underneath - Add a reference to your descriptor (persistence.xml/orm.xml)
- Select your JPA provider from the dropdown
Your JPA-queries should then be validated against your entites.
这篇关于Intellij如何使用spring引导正确配置hql。现在我得到了持久性QL查询的错误检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!