I have this "Parent" class :
@Entity
@Table(name = "parent_table")
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String firstName;
private String lastName;
@OneToMany(fetch=FetchType.LAZY, mappedBy = "parent", cascade = {CascadeType.ALL})
List<Child> children;
}
And, I have the following child class :
@Entity
@Table(name = "children")
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long childId;
@ManyToOne
@JoinColumn(name="parent_id")
private Parent parent;
private String name;
}
I am also sending this as my request body :
{
"firstName": "Test",
"lastName": "Parent",
"children":[{
"name":"jack"
},
{
"name":"jill"
}
]
}
The good news is that is that I can write these children to the database directly from the parent repository, however... when I do my GET, to get a parent, it comes back without the child entities (even though they are in the database, in their table)
SEMI-USEFUL UPDATE (MAYBE?) : I have noticed that the parent_id field in the database for the child records doesn't seem to be getting populated! No idea why!