异常:Batch update returned unexpected row count from update [0]; actual row count: 0;
使用了hibernate的主键生成策略,而在程序中又主动去设置了主键值。<class name="ProductRegion" table="PRODUCT_REGION" lazy="false">
<id name="id" column="PRODUCT_REGION_ID">
<generator class="native" />
</id>
<many-to-one class = "gira.domain.place.Region" name="region" column="PRODUCT_REGION_REGION_ID" />
<many-to-one class = "Product" name="product" column="PRODUCT_REGION_PRODUCT_ID" ></many-to-one>
<property name="index" column="PRODUCT_REGION_INDEX" />
</class>
程序中:
for(Long l:regionIds){
Region region=regionDao.findById(l);
ProductRegion productRegion=new ProductRegion();
productRegion.setProduct(product);
productRegion.setRegion(region);
productRegion.setId(i);
i++;
productRegions.add(productRegion);
}
从而出现异常了