Postgresql throw null value in column violates not-null constraint when using oneToMany relationship in JPA
I tried to test one-to-many relationship for Hibernate. I defined Post and PostComment entities as below: Post.java import javax.persistence.*; import java.util.ArrayList; import java.util.List; @Entity @Table(name = "post") public class Post { @Id @Column(name="post_id") @GeneratedValue(strategy= GenerationType.IDENTITY) private Long postId; @Column(name="title") private String title; @OneToMany(cascade = CascadeType.ALL, mappedBy = "post", orphanRemoval = true) private List<PostComment> comments = new ArrayList<>(); public Post() {}; public Post(String title) { this.title = title; } // Add g
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.