persist problem in cascade using @OneToMany
We are trying to persist an object which has a OneToMany relationship to other objects with CascadeType.ALL
When we persist, the log shows that it creates the INSERT statement with the correct bind variables (sequence-generated REPORT_ID, etc.) for the first object.
The problem happens when it tries to cascade and insert the Many part. The log shows the it tries to create the INSERT statement for the second object but the bind variable for the REPORT_ID is null.
Since we defined the relationship of the OneToMany using the REPORT_ID, we assumed that the REPORT_ID that was auto-generated for the first object would be used for the @Many objects.
What are we missing ??????
First Object:
@Id
@SequenceGenerator(name = "REPORT_HEADER_S", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "REPORT_HEADER_S")
@Column(name = "REPORT_ID", nullable = false)
private Long reportId;
@OneToMany(mappedBy = "report", cascade = { CascadeType.ALL})
private List<Summary> summaryList;
Second Object
@ManyToOne
@JoinColumn(name = "REPORT_ID", referencedColumnName = "REPORT_ID")
private Report report;