Код: Выделить всё
@Entity
public class AutomaticBid {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ave_id", nullable = false)
private Ave ave;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "orig_bid_id", nullable = false)
private Bid orginalBid;
}
Код: Выделить всё
public class Bid {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ave_id", nullable = false)
private Ave ave;
@ManyToOne(fetch = FetchType.LAZY, targetEntity = AutomaticBid.class)
@JoinColumn(name = "automatic_bid")
private AutomaticBid automaticBid;
}
Код: Выделить всё
for (Bid currentBid: ave.getBids()) {
currentBid.setAutomaticBid(null);
}
String deleteAutomBidQueryStr = " delete from AutomaticBid ab where ab.ave.id =:aveId";
Query deleteAutomBidQuery = this.em.createQuery(deleteAutomBidQueryStr);
deleteAutomBidQuery.setParameter("aveId", ave.getId());
int entriesDeletedAb = deleteAutomBidQuery.executeUpdate();
Код: Выделить всё
Cannot delete or update a parent row: a foreign key constraint fails (`hometodeal`.`bid`, CONSTRAINT `FKddu37um70c1liaqbqjn4pjb2g` FOREIGN KEY (`automatic_bid`) REFERENCES `automatic_bid` (`id`))
Код: Выделить всё
currentBid.setAutomaticBid(null);
Подробнее здесь: https://stackoverflow.com/questions/791 ... -row-set-t