查询DSL Q类型类未生成 [英] Query DSL Q type classes not generated
问题描述
我试图在Eclipse Maven项目中使用QueryDSL.这些是依赖项.
I am trying to use QueryDSL in my eclipse maven project. These are the dependencies.
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>my.app.market.DBApp</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<querydsl.version>4.1.4</querydsl.version>
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
</properties>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
此后,我尝试编写查询.
After this I try to write the queries.
@Repository
public class QueryDSLRepo {
@PersistenceContext
private EntityManager em;
public ReportingParamDAO save(final ReportingParamDAO reportingParamDAO) {
em.persist(reportingParamDAO);
return reportingParamDAO;
}
public List<ReportingParamDAO> findreportingParamDAOsByIdQueryDSL(final Integer id) {
final JPAQuery<ReportingParamDAO> query = new JPAQuery<>(em);
final QReportingParamDAO reportingParamDAO = QReportingParamDAO.reportingParamDAO;
return query.from(reportingParamDAO).where(reportingParamDAO.id.eq(id)).fetch();
}
}
但是我得到了错误
QReportingParamDAO cannot be resolved to a type
注意: ReportingParamDAO
是一个实体类.
这意味着未生成我的DAO的Q类型类.我不确定为什么没有生成.我还需要做其他事情吗?我遇到了此帖子,但用户正在使用 IntelliJ
,但我看来无法使其正常工作.有人可以帮帮我吗.谢谢!!
This means that the Q type class for my DAO is not generated. I am not sure why it wasn't generated. Do I need to do something else? I came across this post but the user is working on IntelliJ
and I can't seem to make it work in my case. Can someone please help me. Thanks !!
推荐答案
我已经对您的pom.xml进行了测试.Q类是为我生成的,但是我无法从源代码访问它们.问题是默认情况下,generated-sources不在classpath上.将其添加到类路径中,您将可以在源代码中使用它们.
I have tested with your pom.xml. The Q classes were generated for me but I couldn't access them from my source code. The problem is that the generated-sources is not on classpath by default. Add that on the classpath and you will be able to use them in your source code.
- 检查target/generated-sources目录,以查看类是否确实存在.(您应该能够找到它们,因为我已经使用您的pom.xml进行了测试)
- 如果将目标/生成源添加到类路径,则您的应用程序将运行.但是我认为这不是一个好主意.因为类路径中的所有文件都会被IDE索引,所以您的IDE会变慢.无需为generate-sources文件夹中的所有文件建立索引.因此,将
target/generated-sources/java
添加到classpath并将您的query-dsl插件更改为将生成的Q类更改为target/generated-sources/java
- Check the target/generated-sources directory to see if the classes are actually there. (You should be able to find them because I tested with your pom.xml)
- If you add target/generated-sources to classpath, you application will work. But I don't think that is a good idea. Because all the files in the classpath will be indexed by the IDE and your IDE will be slower. All the files in the generated-sources folder need not be indexed. So add
target/generated-sources/java
to classpath and change your query-dsl plugin to generated Q class totarget/generated-sources/java
这篇关于查询DSL Q类型类未生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!