Hej, próbuje zapisać jednym reguestem dwie encje Car i User. Chce to zrobić jednym requestem tak, żeby User był zagnieżdzony w Car. Podczas próby zapisu dostaje org.hibernate.PersistentObjectException: detached entity passed to persist: repository.model.UserEntity.
@Entity
@Table(name = "cars")
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Getter
@Setter
@Builder
@EntityListeners(AuditingEntityListener.class)
public class CarEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
@EqualsAndHashCode.Include
@Column(updatable = false, insertable = false)
private UUID id;
private String name;
@OneToOne(cascade = ALL)
@JoinColumn(name = "manager_id", referencedColumnName = "id")
private UserEntity manager;
@CreatedDate
@Column(name = "creation_time")
private LocalDateTime creationTime;
@LastModifiedDate
@Column(name = "update_time")
private LocalDateTime updateTime;
}
@Entity
@Table(name = "managers")
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Getter
@Setter
@Builder
@EntityListeners(AuditingEntityListener.class)
public class UserEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
@EqualsAndHashCode.Include
@Column(updatable = false, insertable = false)
private UUID id;
private String name;
private String email;
@Column(name = "phone_number")
private String phoneNumber;
@CreatedDate
@Column(name = "creation_time")
private LocalDateTime creationTime;
@LastModifiedDate
@Column(name = "update_time")
private LocalDateTime updateTime;
}
{
"name": "Fiat",
"user": {
"name": "John Doe",
"email": "[email protected]",
"phoneNumber": "+1234567890"
}
}