Spring Boot QueryDsl returns Caused by: java.lang.Unsupporte



代码如下

QContinent continent = QContinent.continent;
JPAQuery query = new JPAQuery(entityManager);

query.from(continent).where(continent.name.eq("www"));
List<Object> fetch = query.fetch();
System.err.println("===" + fetch);

这返回
原因:java.lang.UnsupportedOperationException: null at java.util.Collections$UnmodifiableMap.put(Collections.java:1457( ~[na:1.8.0_191] at com.querydsl.jpa.JPQLSerializer.visitConstant(JPQLSerializer.java:327( ~[querydsl-jpa-4.2.1.jar:na] at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:221( ~[querydsl-core-4.3.1.jar:na] at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:36( ~[querydsl-core-4.3.1.jar:na] at com.querydsl.core.types.ConstantImpl.accept(ConstantImpl.java:140( ~[querydsl-core-4.3.1.jar:na]

正如@user3388770所建议的那样,原因是版本不匹配。通常,在您的pom.xml/build.gradle中,不要指定Spring已经带来的依赖项版本,除非您出于某种原因确实需要它。

您可以在此处找到使用/兼容的配置文件:https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-dependency-versions.html(根据您的 Spring 版本更改版本(

如果出现错误,依赖项应如下所示(build.gradle(:

plugins {
id "org.springframework.boot" version "2.3.1.RELEASE"
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
...
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
...
dependencies {
annotationProcessor(
...
//some put a version below before ":jpa"; dont.
"com.querydsl:querydsl-apt::jpa"
...
)
//just an example without version numbers as they are delivered with spring boot automatically
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-actuator"
...
compile group: 'org.apache.httpcomponents', name: 'httpclient'
compile 'org.thymeleaf.extras:thymeleaf-extras-java8time'
//but most importantly this below 
compile "com.querydsl:querydsl-jpa"
}

如果您在 POM 基础项目中,请使用这些依赖项和 apt 插件来解决给定版本的此问题

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version></version>
</dependency>
<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/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>

相关内容

最新更新