【问题标题】:JPA Merge entitymanagerJPA 合并实体管理器
【发布时间】:2016-02-10 07:42:12
【问题描述】:

伪代码

     @Entity
     class User
        @Id
        ....
         @ManyToOne
        @JoinColumn(name = "ID_TP_CLASS", insertable = false, updatable = false)
        protected StudentClass studentCLASS;
        ....

User user = entity.merge(user);

在此代码之后,用户实例将重置 studentClass 实例。 在合并之前,studentClass 实例充满了值,在合并之后,studentClass 的实例存在,但 studentClass 中的值为 null 谁能解释一下为什么会这样?

【问题讨论】:

    标签: java jpa merge


    【解决方案1】:

    根据文档:

    将给定实体的状态合并到当前持久化中 上下文。

    返回:状态合并到的托管实例

    您已将 StudentClass 标记为不可插入且不可更新,因此 merge 无法对其执行任何操作。合并后,如果持久化上下文中没有数据,该属性将为空。

    您是否在合并之前从数据库中检索您的实体?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-13
      • 2015-06-22
      • 2014-09-06
      • 2015-06-14
      • 1970-01-01
      • 2019-08-25
      • 2014-11-24
      • 2016-03-24
      相关资源
      最近更新 更多