在service层已经对billWorkdetail进行赋值了,wlBillWorkEntity是外键并且wlBillWorkEntity确定不是空的了。
Iterator<WlBillWorkGoodsEntity> it = wlBillWorkEntity.getWlBillWorkGoodsEntitys().iterator();
int indx = 0;
while(it.hasNext()){
WlBillWorkGoodsEntity billWorkdetail = it.next();

//由系统生成主键Id
String srId2 = StringUtil.getDBKey(commonMsg, type);
billWorkdetail.setSwId(srId2);

billWorkdetail.setWlBillWorkEntity(wlBillWorkEntity);

indx ++;
}

billWorkDAO.insert(wlBillWorkEntity); debug.printEndDebug(ERPConst.ERP_SAVE);
}但是在dao层 hibernate进行插入时:
hibernateTemplate.save(wlBillWorkEntity);
提示:
无法将 NULL 值插入列 'SW_SR_ID',表 'DanDanZongbuv3.dbo.WL_BillWork_Goods';该列不允许空值。INSERT 失败
SW_SR_ID是WL_BillWork_Goods中对wlBillWorkEntity的外键。为什么啊 
WL_BillWork_Goods实体定义外键如下:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SW_SR_ID", nullable = false, insertable = false, updatable = false)
public WlBillWorkEntity getWlBillWorkEntity() {
return this.wlBillWorkEntity;
}