Hibernate - 子类必须在其母类之后绑定

2024-01-04

将 hibernate 升级到 from 版本后4.3.7.最终 to 5.3.18.决赛我收到以下错误

@Entity
@Audited
@AuditPermission(Permission.VIEW_INDIVIDUAL)
public class Individual implements ITemporalEntity {

    @Id
    @Column(name = "Individual_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "Individual_generator")
    @SequenceGenerator(name = "Individual_generator", initialValue = 1, allocationSize = 1, sequenceName = "Individual_id_seq")
    private Long id;
    @Embedded
    private TemporalEntity temporal = new TemporalEntity();
    @Override
    public DateTime getCreateDate() {
     return temporal.getCreateDate();
    }

    @Override
    public void setCreateDate(DateTime createDate) {
     temporal.setCreateDate(createDate);

    }
    .......
    ...

   }

时间实体 class

@Embeddable
public class TemporalEntity {

@Column(updatable = false)
private DateTime createDate;

@Column
private DateTime lastModifiedDate;

@ManyToOne
@JoinColumn(name = "created_by_id", updatable = false)
private AdminUser createdBy;

@ManyToOne
@JoinColumn(name = "last_modified_by_id")
private AdminUser lastModifiedBy;

@Column(nullable = false, columnDefinition = "boolean not null default false")
private boolean deleted = false;

public DateTime getCreateDate() {
    return createDate;
}

public void setCreateDate(DateTime createDate) {
    if (createDate == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null create date not allowed");
    }
    this.createDate = createDate;
}

public DateTime getLastModifiedDate() {
    return lastModifiedDate;
}

public void setLastModifiedDate(DateTime lastModifiedDate) {
    if (lastModifiedDate == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null last modified date not allowed");
    }
    this.lastModifiedDate = lastModifiedDate;
}

public AdminUser getCreatedBy() {
    return createdBy;
}

public void setCreatedBy(AdminUser createdBy) {
    if (createdBy == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null created by not allowed");
    }
    this.createdBy = createdBy;
}

public AdminUser getLastModifiedBy() {
    return lastModifiedBy;
}

public void setLastModifiedBy(AdminUser lastModifiedBy) {
    if (lastModifiedBy == null) {
        //ignore attempts to clear this field
        return;
        //throw new IllegalStateException("Null lastModifiedBy not allowed");
    }
        this.lastModifiedBy = lastModifiedBy;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

}

时间实体界面

public interface ITemporalEntity {

    public DateTime getCreateDate();

    public void setCreateDate(DateTime createDate);

    public DateTime getLastModifiedDate();

    public void setLastModifiedDate(DateTime lastModifiedDate);

    public AdminUser getCreatedBy();

    public void setCreatedBy(AdminUser createdBy);

    public AdminUser getLastModifiedBy();

    public void setLastModifiedBy(AdminUser lastModifiedBy);

    public boolean isDeleted();

    public void setDeleted(boolean deleted);

}

错误堆栈

an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Subclass has to be binded after it's mother class: com.berwick.dal.TemporalEntity
23:11:29,486 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 87) MSC000001: Failed to start service jboss.persistenceunit."bds-core-1.0-SNAPSHOT.war#com.berwick.dal": org.jboss.msc.service.StartException in service jboss.persistenceunit."bds-core-1.0-SNAPSHOT.war#com.berwick.dal": org.hibernate.AssertionFailure: Subclass has to be binded after it's mother class: com.berwick.dal.TemporalEntity
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]

我尝试解决这个问题

add @MappedSuperclass到 TemporalEntity 类 这使得这个错误消失了,但我遇到了更多错误

Duplicate generator name Individual_generator you will likely want to set the property hibernate.jpa.compliance.global_id_generators to false 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198) [wildfly-jpa-21.0.0.Final.jar:21.0.0.Final]

这个问题与链接线程中提出的问题非常相似。错误映射通过接口公开的嵌入式类 https://stackoverflow.com/questions/1071293/hibernate-and-jpa-error-mapping-embedded-class-exposed-through-an-interface

在 @target 注解中写入要嵌入的实体类名称

   @Embedded
   @Target(TemporalEntity.class)
   private ITemporalEntity temporal;
   
   

您不需要通过创建嵌入的新对象来紧密耦合 TemporalEntity

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Hibernate - 子类必须在其母类之后绑定 的相关文章

  • Java new Date() 打印

    刚刚学习 Java 我知道这可能听起来很愚蠢 但我不得不问 System out print new Date 我知道参数中的任何内容都会转换为字符串 最终值是 new Date 返回对 Date 对象的引用 那么它是如何打印这个的呢 Mo
  • 如何默认将 Maven 插件附加到阶段?

    我有一个 Maven 插件应该在编译阶段运行 所以在项目中consumes我的插件 我必须做这样的事情
  • 在画布上绘图

    我正在编写一个 Android 应用程序 它可以在视图的 onDraw 事件上直接绘制到画布上 我正在绘制一些涉及单独绘制每个像素的东西 为此我使用类似的东西 for int x 0 x lt xMax x for int y 0 y lt
  • Java - 将节点添加到列表的末尾?

    这是我所拥有的 public class Node Object data Node next Node Object data Node next this data data this next next public Object g
  • Android MediaExtractor seek() 对 MP3 音频文件的准确性

    我在使用 Android 时无法在eek 上获得合理的准确度MediaExtractor 对于某些文件 例如this one http www archive org download emma solo librivox emma 01
  • 多个 Maven 配置文件激活多个 Spring 配置文件

    我想在 Maven 中构建一个环境 在其中我想根据哪些 Maven 配置文件处于活动状态来累积激活多个 spring 配置文件 目前我的 pom xml 的相关部分如下所示
  • 反射找不到对象子类型

    我试图通过使用反射来获取包中的所有类 当我使用具体类的代码 本例中为 A 时 它可以工作并打印子类信息 B 扩展 A 因此它打印 B 信息 但是当我将它与对象类一起使用时 它不起作用 我该如何修复它 这段代码的工作原理 Reflection
  • Liferay ClassNotFoundException:DLFileEntryImpl

    在我的 6 1 0 Portal 实例上 带有使用 ServiceBuilder 和 DL Api 的 6 1 0 SDK Portlet 这一行 DynamicQuery query DynamicQueryFactoryUtil for
  • 磁模拟

    假设我在 n m 像素的 2D 表面上有 p 个节点 我希望这些节点相互吸引 使得它们相距越远吸引力就越强 但是 如果两个节点之间的距离 比如 d A B 小于某个阈值 比如 k 那么它们就会开始排斥 谁能让我开始编写一些关于如何随时间更新
  • Mockito when().thenReturn 不必要地调用该方法

    我正在研究继承的代码 我编写了一个应该捕获 NullPointerException 的测试 因为它试图从 null 对象调用方法 Test expected NullPointerException class public void c
  • Spring @RequestMapping 带有可选参数

    我的控制器在请求映射中存在可选参数的问题 请查看下面的控制器 GetMapping produces MediaType APPLICATION JSON VALUE public ResponseEntity
  • 无法解析插件 Java Spring

    我正在使用 IntelliJ IDEA 并且我尝试通过 maven 安装依赖项 但它给了我这些错误 Cannot resolve plugin org apache maven plugins maven clean plugin 3 0
  • 在两个活动之间传输数据[重复]

    这个问题在这里已经有答案了 我正在尝试在两个不同的活动之间发送和接收数据 我在这个网站上看到了一些其他问题 但没有任何问题涉及保留头等舱的状态 例如 如果我想从 A 类发送一个整数 X 到 B 类 然后对整数 X 进行一些操作 然后将其发送
  • 如何将 pfx 文件转换为 jks,然后通过使用 wsdl 生成的类来使用它来签署传出的肥皂请求

    我正在寻找一个代码示例 该示例演示如何使用 PFX 证书通过 SSL 访问安全 Web 服务 我有证书及其密码 我首先使用下面提到的命令创建一个 KeyStore 实例 keytool importkeystore destkeystore
  • 使用Caliper时如何指定命令行?

    我发现 Google 的微型基准测试项目 Caliper 非常有趣 但文档仍然 除了一些示例 完全不存在 我有两种不同的情况 需要影响 JVM Caliper 启动的命令行 我需要设置一些固定 最好在几个固定值之间交替 D 参数 我需要指定
  • 仅将 char[] 的一部分复制到 String 中

    我有一个数组 char ch 我的问题如下 如何将 ch 2 到 ch 7 的值合并到字符串中 我想在不循环 char 数组的情况下实现这一点 有什么建议么 感谢您花时间回答我的问题 Use new String value offset
  • 如何在桌面浏览器上使用 webdriver 移动网络

    我正在使用 selenium webdriver 进行 AUT 被测应用程序 的功能测试自动化 AUT 是响应式网络 我几乎完成了桌面浏览器的不同测试用例 现在 相同的测试用例也适用于移动浏览器 因为可以从移动浏览器访问 AUT 由于它是响
  • 玩!框架:运行“h2-browser”可以运行,但网页不可用

    当我运行命令时activator h2 browser它会使用以下 url 打开浏览器 192 168 1 17 8082 但我得到 使用 Chrome 此网页无法使用 奇怪的是它以前确实有效 从那时起我唯一改变的是JAVA OPTS以启用
  • 有没有办法为Java的字符集名称添加别名

    我收到一个异常 埋藏在第 3 方库中 消息如下 java io UnsupportedEncodingException BIG 5 我认为发生这种情况是因为 Java 没有定义这个名称java nio charset Charset Ch
  • 当我从 Netbeans 创建 Derby 数据库时,它存储在哪里?

    当我从 netbeans 创建 Derby 数据库时 它存储在哪里 如何将它与项目的其余部分合并到一个文件夹中 右键单击Databases gt JavaDB in the Service查看并选择Properties This will

随机推荐