在同一个事务下,插入店铺之后,再进行更新操作找不到这个数据。
来源:4-5 店铺注册之Service层的实现
weixin_慕移动3067831
2019-06-26
老师你好,在同一个事务下,我插入店铺之后,再进行更新店铺,插入成功然后更新失败,最后定位问题到在这个事务下查询不到之前插入的店铺,我用的数据库是Oracle,查询和更新方法都测过没问题,老师帮忙看看。
`@Override
@Transactional(propagation=Propagation.REQUIRED)
public ShopExcution addShop(Shop shop, File shopImg) {
//判断传入的店铺信息是否为空
if (shop == null) {
return new ShopExcution(ShopStateEnum.NULL_SHOP);
}
try {
//给shop赋值
shop.setEnableStatus(0); //审核中
shop.setCreateTime(new Date());
shop.setLastEditTime(new Date());
int effectedNum = shopDao.insertShop(shop);
if (effectedNum <= 0) {
throw new ShopOperationException("店铺创建失败");
}else {
//店铺创建成功且当有图片传入时
if (shopImg != null) {
//存储图片
try {
addShopImg(shop,shopImg);
} catch (Exception e) {
throw new ShopOperationException("addShopImg error:" + e.getMessage());
}
Long aString = shopDao.selectShopById(shop.getShopId());
//更新店铺的图片的地址
effectedNum = shopDao.updateShop(shop);
if (effectedNum <= 0) {
throw new ShopOperationException("更新图片地址失败");
}
}
}
} catch (Exception e) {
throw new ShopOperationException("add shop error" + e.getMessage());
}
return new ShopExcution(ShopStateEnum.CHECK, shop);
}
`
写回答
1回答
-
翔仔
2019-06-27
同学好,可以设置断点看看插入成功后,有没有返回shopid?
022019-06-28
相似问题