我试图在我的Kotlin项目中实现Hibernate 6,但我得到以下错误:Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/ReflectionManager Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
这是我的版本。gradle.kts:
plugins {
kotlin("jvm") version "1.9.0"
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.10")
// https://mvnrepository.com/artifact/org.javacord/javacord
implementation("org.javacord:javacord:3.8.0")
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation("com.google.code.gson:gson:2.10.1")
// https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-core/6.3.1.Final
implementation("org.hibernate.orm:hibernate-core:6.3.1.Final")
// // https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
// implementation("org.xerial:sqlite-jdbc:3.43.0.0")
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
implementation("org.apache.logging.log4j:log4j-core:2.20.0")
// // https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-community-dialects
// implementation("org.hibernate.orm:hibernate-community-dialects:6.3.1.Final")
// https://mvnrepository.com/artifact/com.h2database/h2
implementation("com.h2database:h2:2.2.224")
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(8)
}
这是我的代码:
fun main() {
val registry = StandardServiceRegistryBuilder().configure().build()
val sessionFactory = MetadataSources(registry).buildMetadata().buildSessionFactory()
val session = sessionFactory.openSession()
session.beginTransaction()
session.persist(Account(829707526215172136L, 639095276619169813L, 1337))
session.transaction.commit()
}
我已经尝试过实现hibernate-commons-annotations,因为这是别人的解决方案,但是没有成功。
1条答案
按热度按时间bihw5rsg1#
我打赌你需要导入
hibernate-common-annotations
库才能使其工作,现在它在你的gradle构建文件中丢失了:https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations