java – org.postgresql.util.PSQLException:错误:“category_id”列中的空值违反了非空约束

我有一个奇怪的问题:我试图在我的数据库中保存用户,这个用户有一个技能列表.这些技能已经在数据库中,链接的类别和类别具有链接的域.结构如下:当我打印申请人的技能清单时我有这个:skills=[Skill{categories=[Cat...

我有一个奇怪的问题:我试图在我的数据库中保存用户,这个用户有一个技能列表.这些技能已经在数据库中,链接的类别和类别具有链接的域.结构如下:

当我打印申请人的技能清单时我有这个:

skills=[Skill{categories=[Category{domains=[Domain{id=4, name=DevOps}], id=13, name=BackEnd}], id=23, name=Java}, Skill{categories=[Category{domains=[Domain{id=4, name=DevOps}], id=13, name=BackEnd}], id=24, name=C}],

这是制作申请人和技能之间联系的表格:

但是当我试图保存申请人时,我有这个Détail:失败的行包含(23,null,null,499).有人可以解释一下吗?我正在使用jpa注释开发spring应用程序.

编辑1:

申请人身份:

@Entity
@Table(name = "ATS_APPLICANT")
public class ApplicantEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "home", unique = false, nullable = true)
    private Boolean home;

    @Column(name = "anonymous", unique = false, nullable = true)
    private Boolean anonymous;

    @Enumerated(EnumType.STRING)
    @Column(name = "job_type")
    private JobType jobType;

    @Column(name = "min_salary", unique = false, nullable = true)
    private Integer minSalary;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(unique = true)
    private UserEntity user;

    @OneToMany(targetEntity = ApplicantWorkExperienceEntity.class, cascade = CascadeType.ALL)
    private List<ApplicantWorkExperienceEntity> applicantWorkExperiences = new ArrayList<ApplicantWorkExperienceEntity>();

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
    @JoinTable(name = "ATS_APPLICANT_SKILL", joinColumns = @JoinColumn(name = "applicant_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "skill_id", referencedColumnName = "id"))
    private List<SkillEntity> skills = new ArrayList<SkillEntity>();

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "ATS_APPLICANT_LOCATION", joinColumns = @JoinColumn(name = "applicant_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "location_id", referencedColumnName = "id"))
    private List<LocationEntity> locations = new ArrayList<LocationEntity>();

技能实力:

@Entity
@Table(name = "ATS_SKILL")
public class SkillEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Size(min = 1, max = 42)
    @Column(name = "name", length = 42, nullable = false, unique = true)
    private String name;

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "ATS_SKILL_CATEGORY", joinColumns = @JoinColumn(name = "skill_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "category_id", referencedColumnName = "id"))
    private List<CategoryEntity> categories = new ArrayList<CategoryEntity>();

CategoryEntity:

@Entity
@Table(name = "ATS_CATEGORY")
public class CategoryEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Size(min = 1, max = 42)
    @Column(name = "name", length = 42, nullable = false, unique = true)
    private String name;

    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(name = "ATS_CATEGORY_DOMAIN", joinColumns = @JoinColumn(name = "category_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "domain_id", referencedColumnName = "id"))
    private List<DomainEntity> domains = new ArrayList<DomainEntity>();

编辑2:
DomainEntity:

@Entity
@Table(name = "ATS_DOMAIN")
public class DomainEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Size(min = 1, max = 42)
    @Column(name = "name", length = 42, nullable = false, unique = true)
    private String name;

解决方法:

我通过对技能使用@ElementCollection注释获得了成功.

本文标题为:java – org.postgresql.util.PSQLException:错误:“category_id”列中的空值违反了非空约束

基础教程推荐