object references an unsaved transient instance - save the transient instance be

object references an unsaved transient instance - save the transient instance before flushing:..........

 

在Entity设置了单向的 ManyToMany, 级联新增的时候发现报错了

    @ManyToMany(cascade = { CascadeType.REFRESH, CascadeType.MERGE })  
    @JoinTable(name = "t_Testcase_TestScript", joinColumns = { @JoinColumn(name = "caseId") }, inverseJoinColumns = { @JoinColumn(name = "scriptId") })  
    private Set<TestScript> testScripts = new HashSet<TestScript>();  

 

原因:级联对象没有被保存

 

解决办法:

cascade = { CascadeType.ALL }

 

或者把级联对象先保存

 

你可能感兴趣的:(reference)