I have Building entity:
@Entity
@Data
public class Building {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "building_id", nullable = false, unique = true)
private int buildingId;
@Column(name = "name", nullable = false, length = 255)
private String name;
@Column(name = "address", nullable = false, length = 255)
private String address;
@Column(name = "deleted", nullable = false)
private Boolean isDeleted = Boolean.FALSE;
@OneToMany(mappedBy = "building", cascade = CascadeType.MERGE)
private List<Floor> floorList;
}
And Floor entity:
@Entity
@Data
public class Floor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "floor_id", nullable = false, unique = true)
private int floorId;
@Column(name = "name", nullable = false, length = 255)
private String name;
@Column(name = "deleted")
private Boolean isDeleted = Boolean.FALSE;
@ManyToOne
@JoinColumn(name = "building_id")
private Building building;
}
So one Building
has many Floors
and i have trouble when inserting data in Building
to update building_id
in Floor
entity (floor is populated table). This is example of my Building payload:
{
"name": "Some name",
"address": "Some address",
"floorList": [
{
"floorId": 1
}
]
}
I guess the problem can be cascading, but maybe i am completly wrong. So what can i do to solve this problem?