![](/img/trans.png)
[英]Spring Boot QueryDsl java.lang.UnsupportedOperationException
[英]Spring Boot QueryDsl returns Caused by: java.lang.UnsupportedOperationException: null
代码如下
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);
这返回
Caused by: 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.Z93F725A07423FE1C889F448B33D2 1F46Z:140) ~[querydsl-core-4.3.1.jar:na]
正如@user3388770 所建议的那样,原因是版本不匹配。 通常,在您的pom.xml
/ build.gradle
中不要指定依赖项的版本,除非您出于某种原因确实需要它,否则 Spring 已经带来了。
You can find the used/compatible depencies here: https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-dependency-versions.html (change the version according to your 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.