我正在尝试使用POST Rest API将新对象添加到h2内存数据库中。我收到此错误:嵌套异常是org.hibernate.exception.ConstraintViolationException
在我的费用实体中,我已经放置了@ManyToOne(cascade = CascadeType.ALL),所以在创建费用对象之前不应该创建类别对象,不是吗?
提前致谢。这是我的实体:公共课程费用{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
private String description;
@Column(name = "expense_date")
private Instant expenseDate;
@Column(name = "location")
private String location;
@ManyToOne(cascade={CascadeType.ALL})
@Nullable
@JoinColumn(name = "category_id", referencedColumnName = "id", nullable = false)
private Category category;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
@Nullable
@JsonIgnore
private User user;}
类别类别公共类别类别{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
@NonNull
private String name;}
用户类别:公共类别用户{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", updatable = false, nullable = false)
private Long id;
private String name;
private String email;}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。