DELETE FROM bookings as b WHERE b.check_out = CURRENT_DATE;
Cannot delete or update a parent row: a foreign key constraint fails (online_booking_app.booked_rooms, CONSTRAINT FK3x1lpikb2vk75nx41lxhdicvn FOREIGN KEY (booking_id) REFERENCES bookings (id))
CascadeType.ALL
BookingEntity
@Entity @Table(name = "bookings") public class BookingEntity extends BaseEntity { @OneToMany(mappedBy = "booking",cascade = CascadeType.ALL, orphanRemoval = true) private List<BookedRoomsEntity> bookedRooms = new ArrayList<>(); private String firstName; private String lastName; public List<BookedRoomsEntity> getBookedRooms() { return bookedRooms; } public BookingEntity setBookedRooms(List<BookedRoomsEntity> bookedRooms) { this.bookedRooms = bookedRooms; return this; }
BookedRoomsEntity
@Entity @Table(name = "booked_rooms") public class BookedRoomsEntity extends BaseEntity { @ManyToOne() private BookingEntity booking; public BookingEntity getBooking() { return booking; } public BookedRoomsEntity setBooking(BookingEntity booking) { this.booking = booking; return this; }
orphanRemoval=true
CascadeType.All
ON DELETE CASCADE
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)