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();
}
}
But I get the error
QReportingParamDAO cannot be resolved to a type
Note: ReportingParamDAO
is an entity class.
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 !!
mvn -X clean install
. That will give you better info on what is happening in that plugin. If possible, can you post the relevant console output for this plugin? – Sectarianism