老师你好,在同一个事务下,我插入店铺之后,再进行更新店铺,插入成功然后更新失败,最后定位问题到在这个事务下查询不到之前插入的店铺,我用的数据库是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);
}
`
SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需
了解课程