PSQLException: ОШИБКА: UPDATE или DELETE в таблице "tickets" нарушает ограничение внешнего ключа "ticket_flights_ticket_no_fkey" таблицы "ticket_flights"
Detail: На ключ (ticket_no)=(0005432000860) всё ещё есть ссылки в таблице "ticket_flights".
Возможно чтото с аннотациями не так
public class Booking {
@Id
@Column(name = "book_ref", length = 6, nullable = false)
private String bookRef;
@Column(name = "book_date", nullable = false)
private ZonedDateTime bookDate;
@Column(name = "total_amount", nullable = false, precision = 10, scale = 2)
private BigDecimal totalAmount;
@OneToMany(mappedBy = "booking",
cascade = CascadeType.ALL,
fetch = FetchType.LAZY,
orphanRemoval = true)
private Set<Ticket> tickets;
}
public class Ticket {
@Id
@Column(name = "ticket_no", nullable = false)
Long ticketNo;
@Column(name = "book_ref", insertable=false, updatable=false, nullable = false)
String bookRef;
@Column(name = "passenger_id", nullable = false)
Long passengerId;
@Column(name = "passenger_name", nullable = false)
String passengerName;
@Column(name = "contact_data", columnDefinition = "jsonb")
@Convert(converter = MapConverter.class)
@JsonProperty("contact_data")
Map<String, String> contactData;
@ManyToOne
@JoinColumn(name = "book_ref", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
Booking booking;
@ManyToMany
@JoinTable(
name = "ticket_flights",
joinColumns = @JoinColumn(name = "ticket_no"),
inverseJoinColumns = @JoinColumn(name = "flight_id"))
Set<TicketFlight> ticketFlights;
}
DELETE FROM tickets WHERE book_ref = ?;
DELETE FROM bookings WHERE book_ref = ?;