如何在hibernate中更新级联列

时间:2017-02-27 07:30:24

标签: hibernate jpa

我有一个实体" feed"这是另一个实体的父母"记录"如下

@OneToMany(mappedBy="feed",cascade=CascadeType.ALL)
    private List<Record> Record;

参考列是feed_id和序列

我想要的是,当我更改序列并保存Feed实体时,我的记录序列也应该更新。

Map<String,String> error;
Feed feed = _objMapperDataService.getSequence(a_mapperFeed.getPROJECT_ID‌​(),a_mapperFeed.getF‌​DID());
int seqNo = feed.getFeedSequence()+1;
feed = _objMapperDataService.getFeedBySequence(a_mapperFeed.getPROJ‌​ECT_ID(),a_mapperFee‌​d.getFDID());
feed.setFeedSequence(seqNo); 
error = _objMapperDataService.saveOrUpdateFeed(feed);
if(error.get("success").equals("true")){ 
     a_mapperFeed.setID(null);
     a_mapperFeed.setSEQUENCE(0);
     error = _objMapperDataService.saveOrUpdateFeed(mapperFeedToFeed(a_ma‌​pperFeed)); 
}
return error;

我尝试了cascadeAll但它不起作用并在保存时出现以下错误

org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint ["FKCU5674BI4F1DDPKM9QV2EQKI9: PUBLIC.RECORD FOREIGN KEY(FDID, SEQUENCE) REFERENCES PUBLIC.FEED(FDID, SEQUENCE) (0, 0)";\

0 个答案:

没有答案