I want to share primary key using one-to-one relation.
and when parents are persisted, their children also be persisted (CascadeType.ALL)
this is my code
@Entity
@Table(name = "TB_PAR")
@Data
public class Par implements Serializable {
@Id
@Column(name = "ID")
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private UUID id;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "ID", referencedColumnName = "ID")
private Child child;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "TB_CHILD")
public class Child implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "ID", referencedColumnName = "ID")
private Par par;
}
//Session initialize
...
PAR par = new PAR();
Child child = new child();
par.setChild(child);
session.persist(par);
...
then, print a warning that a null value cannot be inserted into the id column.
(depend on rdbms / my db is oracle so I can see ORA-01400)
how can i fix it?