从 Spring Boot 2.7.12 升级到 3.1.0 后出现 hibernate InstantiationException

问题描述 投票:0回答:1

自从spring boot版本升级到3.1.0并随后将javax替换为jakarta后,由于以下错误,我无法编译集成测试(并且在应用程序运行时会出现问题):

Caused by: org.springframework.orm.jpa.JpaSystemException: Unable to locate constructor for embeddable : com.example.nccn.aggregator.db.foo.FooEntityId

Caused by: org.hibernate.InstantiationException: Unable to locate constructor for embeddable : com.example.nccn.aggregator.db.foo.FooEntityId 

实体看起来像这样:

@Embeddable
class FooEntityId(
    @Column(name = "id")
    var id: Long,
) : Serializable

并且它是a的一部分:

@Embeddable
class FooFooEntityId(
    @Embedded
    var fooEntityId: FooEntityId,

[...]
) : Serializable

用于:

@Entity
@Table(name = "foo_table", schema = "example")
data class ExampleEntity(
    @EmbeddedId
    var id: FooFooEntityId? = null,
[...]
) 

对于所有列出的实体和其他定义的实体,信息出现在开头,这是以前不存在的 -

No default (no-argument) constructor for class: com.example.nccn.aggregator.db.foo.FooEntityId (class must be instantiated by Interceptor)

当前设置:
Spring Boot 3.1.0
Java 17
科特林 1.7.0
另外,我使用插件:
科特林:
-全开
-春天
-无参数
-jpa
这些插件向我保证,除其他外,应该生成无参构造函数,这是 hibernate 所需要的。
我检查了字节码并反编译了它 - 有无参构造函数。

spring spring-boot hibernate kotlin jpa
1个回答
0
投票

我遇到了同样的问题:确实,正如建议的那样 @Fossan,因为我使用 lombok,所以我省略了无参构造函数(@NoArgsConstructor)。插入后,错误已解决。我希望这对你有帮助,问候

© www.soinside.com 2019 - 2024. All rights reserved.