相关疑难解决方法(0)

喜欢构成而不是继承?

为什么喜欢构图而不是继承呢?每种方法都有哪些权衡取舍?什么时候应该选择继承而不是作文?

language-agnostic oop inheritance composition aggregation

1538
推荐指数
23
解决办法
29万
查看次数

作为实体的密封类

我对密封课程有疑问。如果我从 docker 运行我的应用程序,它工作得很好,但如果我在 IntelliJ 中执行相同的操作,我会遇到以下异常:

java.lang.IncompatibleClassChangeError: class com.nemethlegtechnika.products.model.Attribute$HibernateProxy$D0WxdNVz cannot inherit from sealed class com.nemethlegtechnika.products.model.Attribute

如果我使用抽象类而不是密封类,那么在 IntelliJ 和 Docker 中都不会出现错误。你们能帮我找到问题的根源吗?

提前致谢,祝您有美好的一天!:)

课程:
package com.nemethlegtechnika.products.model

import jakarta.persistence.*
import org.hibernate.annotations.DiscriminatorFormula

@Entity
@Table(name = "attribute")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula("case when stringValues is not null then 'string' else 'boolean' end")
sealed class Attribute : BaseEntity() {

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "product_id")
    val product: Product? = null

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
    @JoinColumn(name = "group_id")
    val group: Group? = null

    abstract …
Run Code Online (Sandbox Code Playgroud)

spring hibernate kotlin docker sealed-class

5
推荐指数
1
解决办法
993
查看次数