所以我试图使用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.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中的持久性工具,可以执行一个简单的查询:
HQL&GT;来自用户
它会产生以下错误:
[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:
.....
正如您所看到的,我有点迷失......这些设置有什么问题?
答案 0 :(得分:8)
Project structure
设置(ctrl + alt + shift + s)中,选择Facets
和Add
。JPA
Modules
视图中,选择相关模块以及JPA
构面
然后,您的JPA查询应该针对您的网站进行验证。