【问题标题】:Hibernate canot insert null into audit column on deleteHibernate 无法在删除时将 null 插入审计列
【发布时间】:2012-04-23 22:28:24
【问题描述】:

我最近在我的 user 和 user_audit 表中添加了一个新列“PASSWORD_RESET_REQUIRED”。

当我尝试删除用户时不会 我收到一条错误消息:

无法将 NULL 插入 ("USER_AUD"."PASSWORD_RESET_REQUIRED")

@Entity
@Table(name = "sec_user", schema = "RZUL_DATA")
//Override the default Hibernate delete and set the termination date rather than     deleting the record from the db.
@SQLDelete(sql = "UPDATE RZUL_DATA.sec_user SET trmn_dt = sysdate  WHERE user_id = ?")

@Audited
public class User {

@NotEmpty
@Column(name = "password_reset_required", updatable = true, insertable = true)
private String isPasswordResetRequired;

 ... other properties
}

我的UserDao删除方法:

@Override
public boolean deleteUser(final User user) {
    sessionFactory.getCurrentSession().delete(user);
   NOTE: Till this point I can see the user.isPasswordResetRequired an a non null.
    return true;
}

我可能遗漏了哪些部分?

【问题讨论】:

    标签: hibernate hibernate-annotations audit-tables


    【解决方案1】:

    确保您的 *_HISTORY 表没有 NOT NULL 数据列。

    【讨论】:

      【解决方案2】:

      当您尝试删除项目时,Hibernate 尝试将 Child 表上的外键列设置为 null,因为它不能为 null,所以您使用的 SQL 技术会出错。试试

      @Cascade(value=CascadeType.ALL)
      

      cannot insert null in one to many relatioship hibernate annotation

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-02-18
        • 2013-07-06
        • 1970-01-01
        • 2011-08-23
        • 2020-06-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多