Home QuerydslPredicate with spring-boot-starter-jpa
Reply: 0

QuerydslPredicate with spring-boot-starter-jpa

user15964
1#
user15964 Published in September 20, 2018, 1:23 pm

I have a problem with autogenerating Q classess in com.querydsl. I know that there are possible mistakes with compatibility between com.query.dsl and spring-boot-jpa but i tried lots of version without any positive result. Here is my pom.xml

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1212.jre7</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.12</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
        <version>1.4.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>21.0</version>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.9.3</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.6.1</version>
    </dependency>
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>4.0.7</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <id>process-common-model</id>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/apt</outputDirectory>
                        <processors>
                            <processor>com.query.apt.jpa.JPAAnnotationProcessor</processor>
                        </processors>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>4.0.7</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The error

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.jpa.repository.support.QueryDslJpaRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Did not find a query class com.coig.prek.webservice.modules.quiz.entiry.QQuiz for domain class com.coig.prek.webservice.modules.quiz.entiry.Quiz! at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepositoryViaReflection(RepositoryFactorySupport.java:365) ~[spring-data-commons-1.13.0.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:101) ~[spring-data-jpa-1.11.0.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:81) ~[spring-data-jpa-1.11.0.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:199) ~[spring-data-commons-1.13.0.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.0.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.0.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.0.RELEASE.jar:na] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] ... 47 common frames omitted Caused by: java.lang.IllegalArgumentException: Did not find a query class com.coig.prek.webservice.modules.quiz.entiry.QQuiz for domain class com.coig.prek.webservice.modules.quiz.entiry.Quiz! at org.springframework.data.querydsl.SimpleEntityPathResolver.createPath(SimpleEntityPathResolver.java:63) ~[spring-data-commons-1.13.0.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.(QueryDslJpaRepository.java:84) ~[spring-data-jpa-1.11.0.RELEASE.jar:na] at org.springframework.data.jpa.repository.support.QueryDslJpaRepository.(QueryDslJpaRepository.java:68) ~[spring-data-jpa-1.11.0.RELEASE.jar:na] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_111] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_111] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_111] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_111] at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE] ... 56 common frames omitted Caused by: java.lang.ClassNotFoundException: com.coig.prek.webservice.modules.quiz.entiry.QQuiz at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111] at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE] at org.springframework.data.querydsl.SimpleEntityPathResolver.createPath(SimpleEntityPathResolver.java:53) ~[spring-data-commons-1.13.0.RELEASE.jar:na] ... 63 common frames omitted

Repository:

@Repository
public interface QuizRepository extends PagingAndSortingRepository<Quiz, Long>, QueryDslPredicateExecutor<Quiz> {
}

And Entity:

@javax.persistence.Entity
@Table(name = "QUIZ", uniqueConstraints = {
        @UniqueConstraint(columnNames = "NAME")
})
@ToString
public class Quiz extends Entity{

    @Column(name = "NAME")
    private @Setter @Getter String name;
    @Column(name = "TYPE")
    private @Setter @Getter Integer type;
    @Column(name = "TIME")
    private @Setter @Getter Long time;
    @JsonProperty(value = "branch")
    @Column(name = "BRANCH")
    private @Setter @Getter Integer branch;

    @OneToMany
    private @Setter @Getter Set<Question> questions;

    public Quiz() {}

}

Can you tell me if I missing something, or what I am doing wrong? Thanks for any help.

share|improve this question
  • For starters stop mixing spring boot versions (1.5.1 and 1.4.3 and?). Never mix versions of a framework (regardless of the framework). – M. Deinum Feb 13 '17 at 7:20
  • Yes, my mistake, forgot to fix the code after checking another solution found in google. (It was not fixing my main problem) – rdabrowski Feb 13 '17 at 7:24

1 Answer 1

active oldest votes
up vote 1 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.425642 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO