Reputation: 41
i want to use querydsl in springboot(kotlin), but when i test querydsl by useing findOne(), there is error..
@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:
i think that there is some mapping error QAccount -> Account...
is there anyone to check?
Upvotes: 1
Views: 528
Reputation: 41
I solved the problem. the reason is plugin version problem.. when i changed version to latest, querydsl doing well.
this is my dependency of build.gradle.kts
api("com.querydsl:querydsl-jpa:4.3.1")
kapt("com.querydsl:querydsl-apt:4.3.1:jpa")
and, you can check the version of plugin here. https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/appendix-dependency-versions.html
Upvotes: 3