我用MySQL实现了hibernate项目,工作正常。但是我的客户想在Oracle 11g中使用它,但是下面的代码却抛出了这个错误。
引起:java.sql.SQLIntegrityConstraintViolationException:ORA-02291:违反了完整性约束(GOPI.SYS_C007099) - 未找到父密钥
这是我的以下代码与@oneToMany @ManyToOne关系
我有3个实体
@Entity Process have
@oneToMany with
Process_analysis And
@oneToMany
Process_Steps
以下是我如何坚持
Process_Steps proSteps=new Process_Steps ();
List<Process_analysis> pro_Anlist =new ArrayList<Process_analysis>();
java.util.Date date=new java.util.Date();
this.bean.setCancelled_Flg('F');
this.bean.setUser_Id("xyz");
this.bean.setpro_Status("xyz");
this.bean.setPro_Description("dsfdfdfsdf");
this.bean.setLast_Updated_Date(new Timestamp(date.getTime()));
proService.merge(this.bean); //Persisting or merging Process Entity
for(int i=0;i<3;i++){
Process_analysis proAn=new Process_analysis();
proAn.setCase_Protocal_Id("CASE:"+i);
proAn.setPro(this.bean);
proAnService.persist(proAn); //Persisting Each process analysis for Process NOTE:Throws Error Here
pro_Anlist.add(proAn);
}
proSteps.setRemarks("The StackOverflow");
proSteps.setStart_Time(new Timestamp(date.getTime()));
proSteps.setEnd_Time(new Timestamp(date.getTime()));
proSteps.setPro(this.bean); //Setting Foreign key of Process
proStepsService.persist(proSteps);
this.bean.getProAna().addAll(pro_Anlist);
this.bean.getProSteps().add(proSteps);
proService.merge(this.bean);`
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pro_que_seq")
@SequenceGenerator(name="pro_que_seq",sequenceName="pro_que_seq")
@Column(name="Pro_Id")
private Long Pro_Id;
public Long getPro_Id() {
return Pro_Id;
}
public void setPro_Id(Long pro_Id) {
Pro_Id = pro_Id;
}
@ElementCollection
@OneToMany(cascade=CascadeType.MERGE, fetch=FetchType.EAGER,mappedBy="Pro",targetEntity=ProInSteps.class)
private Collection<ProInSteps> ProInSteps=new LinkedHashSet<ProInSteps>();
@ElementCollection
@OneToMany(cascade=CascadeType.MERGE, fetch=FetchType.EAGER,mappedBy="Pro",targetEntity=ProAnalysis.class)
private Collection<ProAnalysis> ProAnalysis=new LinkedHashSet<ProAnalysis>();
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pro_an_seq")
@SequenceGenerator(name="pro_an_seq",sequenceName="ana_pro_seq")
private Long Analysis_Id;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="Pro_Id")
private Process Pro;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="in_step_seq")
@SequenceGenerator(name="in_step_seq",sequenceName="pro_instep_seq")
private Long Pro_Step_Id;
private Timestamp Start_Time;
private Timestamp End_Time;
@ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="Pro_Id")
private Process Pro;