hibernate报错object references an unsaved transient instance - save the transient instance before flushing: com.king3d.manage.domain.Sys2;
从URL传入参数,会报这个错误,但是JUNIT中测试就没有任何问题,不知道原因。action与service代码如下
[code="java"]
@Action(results = { @Result(type = "json") }, value = "saveSub")
public String saveSub() throws Exception {
Tools.decodeObject(sys2);
dic.saveDictionaryData(sys2);
resultStatus = "true";
return "success";
[/code]
[code="java"]
@Transactional
public void saveDictionaryData(Sys2Vo sys2vo) throws Exception {
Sys2 entry = new Sys2();
BeanUtils.copyProperties(sys2vo, entry);
if(sys2vo.getId() > 0){
this.sys2Dao.update(entry);
}else{
this.sys2Dao.save(entry);
}
sys2vo.setId(entry.getId());
}
[/code]
[code="java"]
public class Sys2 {
@Id
@SequenceGenerator(name="sys2",sequenceName="SEQ_SYS2_ID",allocationSize=1 )
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="sys2")
private int id;
private int key;
private String value;
@ManyToOne
@JoinColumn(name="SYS1_ID")
private Sys1 sys1;
@ManyToOne
@JoinColumn(name="PARENT_ID")
private Sys2 sys2;
@OneToMany(mappedBy="sys2")
private List sys2s=new ArrayList();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Sys1 getSys1() {
return sys1;
}
public void setSys1(Sys1 sys1) {
this.sys1 = sys1;
}
public Sys2 getSys2() {
return sys2;
}
public void setSys2(Sys2 sys2) {
this.sys2 = sys2;
}
public List getSys2s() {
return sys2s;
}
public void setSys2s(List sys2s) {
this.sys2s = sys2s;
}
}
[/code]