I have several entities
@Entity
@Table(name = "A")
public class A {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "alIdSeq")
@SequenceGenerator(name = "aIdSeq", sequenceName = "a_id_seq", allocationSize = 1)
private Long id;
@JoinColumn(name = "a_id", referencedColumnName = "id")
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
private List<B> b = new ArrayList<>();
}
@Entity
@Table(name = "B")
public class B {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "blIdSeq")
@SequenceGenerator(name = "aIdSeq", sequenceName = "b_id_seq", allocationSize = 1)
private Long id;
}
Example: When I get object A from repo and add new object B to list then repository does not save new object B.
A a = aRepository.findById(someId);
B b = new B();
a.getB().add(B);
Note: Sql table does not contain new B.