JpaSystemException: попытка назначить идентификатор из нулевого свойства «один к одному» Ошибка с Jpa и Hibernate - PullRequest
0 голосов
/ 29 февраля 2020
Resolved [org.springframework.orm.jpa.JpaSystemException: attempted to assign id from null one-to-one property [com.example.bootapp.entity.Employee.user]; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [com.example.bootapp.entity.Employee.user]]

Субъект пользователя

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumn(name = "id")
@JsonIgnore
@Getter @Setter
private Employee employee;

Субъект сотрудника

@OneToOne(fetch = FetchType.LAZY)
@MapsId
@JsonIgnore
private User user;

Заранее спасибо!

1 Ответ

0 голосов
/ 29 февраля 2020

Решено!

user.setEmployee(null); // I added this line
        userCommandService.save(user);
        employee.setUser(user);
        employeeCommandService.save(employee);

При установке значения свойства employee внутри объекта пользователя на null моя ошибка исчезла!

...