我在hibernate中存在级联问题。
我有这两个实体:
@Entity
@Table(name = "testscenario")
public class Testscenario {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false, name = "scenario_id")
Long scenarioId;
@OneToOne(mappedBy = "scenario", cascade = CascadeType.ALL)
private Mapping mapping;
....
@Entity
@Table(name = "mapping")
public class Mapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false, name = "mapping_id")
Long id;
@OneToOne
@JoinColumn(name = "scenario_id", referencedColumnName = "scenario_id")
private Testscenario scenario;
当我尝试存储实体时,子实体的父ID保持为null。这就是我存储实体的方式:
Testscenario testscenario = new Testscenario();
testscenario.setName(scenarioName);
testscenario.setForwarder(forwarder);
Mapping mapping = new Mapping();
mapping.setJar(mappingFileParam.getBytes());
mapping.setJarFilename(mappingFileParam.getOriginalFilename());
mapping.setSourceFormat("sourceFormat");
mapping.setDescription("description");
mapping.setTargetFormat("targetFormat");
testscenario.setMapping(mapping);
testscenarioService.create(testscenario)
我做错了什么?