我想在springboot(kotlin)中使用querydsl,但是当我通过使用findOne()测试querydsl时,出现了错误。
@Entity
data class Account(
val username: String,
val firstName: String,
val lastName: String
) {
@Id
@GeneratedValue
val id: Long? = null
}
interface AccountRepository : JpaRepository<Account, Long>,
QuerydslPredicateExecutor<Account>
@DataJpaTest
class AccountRepositoryTest {
@Autowired
lateinit var accountRepository: AccountRepository
@Test
fun crud() {
accountRepository.save(Account(username = "sooyougkim",
firstName = "sooyoug",
lastName = "kim"))
val predicate: Predicate = QAccount
.account
.firstName
.containsIgnoreCase("sooyoug")
.and(QAccount.account.lastName.startsWith("kim"))
val findOne = accountRepository.findOne(predicate).get()
}
}
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
at com.querydsl.jpa.JPQLSerializer.visitConstant(JPQLSerializer.java:327)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:221)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:36)
at com.querydsl.core.types.ConstantImpl.accept(ConstantImpl.java:140)
.
.
.
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:821)
AccountRepositoryTest > crud() FAILED
java.lang.UnsupportedOperationException at AccountRepositoryTest.kt:31
2020-07-30 09:58:37.653 INFO 21450 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2020-07-30 09:58:37.653 INFO 21450 --- [extShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate:
我认为存在一些映射错误QAccount-> Account ...有没有人要检查?
最佳答案
我解决了问题。
原因是插件版本问题。
当我将版本更改为最新版本时,querydsl表现良好。
这是我对build.gradle.kts的依赖
api("com.querydsl:querydsl-jpa:4.3.1")
kapt("com.querydsl:querydsl-apt:4.3.1:jpa")
并且,您可以在此处检查插件的版本。https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-dependency-versions.html
关于spring-boot - 当我在Kotlin中使用querydsl时,为什么会出现错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63164972/