我正在尝试使用 micronaut 框架创建一个示例应用程序。我创建了一个扩展 JPA 存储库的存储库类
import com.rest.micronaut.Entity.FileEntity;
import io.micronaut.data.annotation.Repository;
import io.micronaut.data.repository.CrudRepository;
@Repository
public interface FileRepository extends CrudRepository<FileEntity, Long> {
}
并使用默认方法从 H2 数据库中保存和获取数据。
当我使用 save 或 find all 方法时,我得到了想要的结果,但是当使用 findById 之类的方法时,它会抛出错误消息
{
"message": "Internal Server Error: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: . near line 1, column 81 [SELECT entity.FileEntity_.id FROM com.rest.micronaut.Entity.FileEntity AS entity.FileEntity_ WHERE (entity.FileEntity_.id = :p1)]"
}
这是我的 build.gradle 文件
plugins {
id("com.github.johnrengelman.shadow") version "6.1.0"
id("io.micronaut.application") version "1.2.0"
}
version "0.1"
group "com.rest.micronaut"
repositories {
mavenCentral()
jcenter()
}
micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.rest.micronaut.*")
}
}
dependencies {
annotationProcessor("org.projectlombok:lombok:1.18.16")
annotationProcessor("io.micronaut:micronaut-validation")
annotationProcessor("io.micronaut.data:micronaut-data-processor")
implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut:micronaut-runtime")
implementation("io.micronaut:micronaut-http-client")
implementation("org.modelmapper:modelmapper:2.3.8")
implementation("io.micronaut.sql:micronaut-jdbc-hikari")
implementation("io.micronaut.sql:micronaut-hibernate-jpa")
runtimeOnly("com.h2database:h2")
compileOnly "org.projectlombok:lombok:1.18.16"
}
mainClassName = "com.rest.micronaut.Application"
java {
sourceCompatibility = JavaVersion.toVersion('1.8')
targetCompatibility = JavaVersion.toVersion('1.8')
}
这是代码存储库的链接