Код: Выделить всё
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed: org.springframework.dao.DataIntegrityViolationException: could not execute statement
[ERROR: insert or update on table "order" violates foreign key constraint "order_customer_id_fkey"
Detail: Key (customer_id)=(0) is not present in table "customer".]
[insert into order (id, order_date, customer_id, total_amount) values (?,?,?,?)];
constraint [order_customer_id_fkey]] with root cause
org.postgresql.util.PSQLException: ERROR: insert or update on table "order" violates foreign key constraint "order_customer_id_fkey"
Код: Выделить всё
@Entity
@Table(name = "order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private LocalDate orderDate;
private BigDecimal totalAmount;
@ManyToOne
@JoinColumn(name = "customer_id")
private Customer customer;
..
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... tion-table