我有一个奇怪的问题:我试图在我的数据库中保存用户,这个用户有一个技能列表.这些技能已经在数据库中,链接的类别和类别具有链接的域.结构如下:当我打印申请人的技能清单时我有这个: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”列中的空值违反了非空约束
基础教程推荐
猜你喜欢
- 三行Java代码实现计算多边形的几何中心点 2023-06-23
- SpringMVC视图转发重定向区别及控制器详解 2022-11-25
- FeignClient中name和url属性的作用说明 2023-02-05
- SpringBoot实现过滤器拦截器的耗时对比 2023-02-05
- Mybatis Plus插入数据后获取新数据id值的踩坑记录 2023-03-31
- 详解Java ReentrantReadWriteLock读写锁的原理与实现 2023-06-16
- 使用@Cacheable缓存解决双冒号::的问题 2023-08-07
- java序列化对象根据不同配置动态改变属性名的方法 2022-11-08
- 使用@ApiModel遇到的问题及解决 2023-01-03
- springboot 集成redis哨兵主从的实现 2023-02-28