Нарушение внешнего ключа при вставке в таблицу «станция»JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Нарушение внешнего ключа при вставке в таблицу «станция»

Сообщение Anonymous »

При попытке вставить объект Order в базу данных PostgreSQL я получаю следующее исключение:

Код: Выделить всё

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»