我的代码:
// 取得此商品编码表
DicProductBarcodeInfo barcodeInfo = (DicProductBarcodeInfo) replaceBarcodeCheckResult
.get(0);

// 判断带编码更换商品是否是同一商品
if (barcodeInfo.getProductId().intValue()
!= dicOutwareOrderAttach.getProductId().intValue())
{
System.out.println("更换商品"
+ dicOutwareOrderAttach.getProductId()
+ "与被更换商品" + barcodeInfo.getProductId()
+ "不是同一个商品!");

return "7";
} /**
 * ******************************************
 * 被更换商品编码状态由销售状态改为库存状态。
 * ******************************************
 */
/*DicProductBarcodeInfo barcodeUpdate = new DicProductBarcodeInfo();

// 属性拷贝
try
{
BeanUtils.copyProperties(barcodeUpdate, barcodeInfo);
}
catch (Exception e){ }*/

// 此商品编码状态由”3-销售状态“更改为”0-库存状态“
barcodeInfo.setProductStsCode("0");
barcodeInfo.setKeepPosition(dicOutwareOrderMain
.getDepotName());
barcodeInfo.setNotes("更换入库!"); // 添加到待修改商品编码集合中
barcodeForUpdateList.add(barcodeInfo);我在这里把Entity的属性改了,但是后面又有其他的情况,程序直接返回了,未提交数据库,但是数据库中记录自动改了,请问怎么回事啊??

解决方案 »

  1.   

    因为你这个时候的对象处于持久化状态中,你修改以后就自动保存了,其实这个时候是更新了HIBERNATE的缓存,还没有提交到数据库。
      

  2.   

    hibernate 事务提交默认是不提交 
    把事务改下就好 commit=true
      

  3.   

    通过hibernate 查询出来的数据默认为 持久状态,也就是说:你对该数据作出的任何操作都将被hibernate自动同步更新到数据库。
      

  4.   

    有Transaction.setAutoCommit设为false