【问题标题】:How to add entity to the databse without adding related entitiy in DB as well?如何将实体添加到数据库而不在数据库中添加相关实体?
【发布时间】:2020-04-21 13:28:50
【问题描述】:

我在添加一个实体时遇到问题,使用 JPA 保存且没有错误:

JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column

因为我向要保存的对象添加了空实体。 我如何保存一个实体并告诉它相关的实体忽略此交易?

例如,我有 student 和 student_info OneToOne 关系。我想保存学生而不是给他分配信息,但是我的 student_info 告诉我:嘿 student_info 列 1 不能为空。

【问题讨论】:

    标签: java sql spring jpa


    【解决方案1】:

    你不能!

    如果数据库存在 Not Null、主键或外键等约束,则只有在满足约束时才能将数据保存到此表中。

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多