I'm running the following junit test :
Code:
public void testSaveAndUpdateProduct() throws Exception {
PopulateProduct pProd= new PopulateProduct();
List products = pProd.getProducts(TEST_FILENAME);
Product prod = (Product)products.get(0);
String prodCode = prod.getProductCode();
Integer srvId = prod.getServiceId();
[b] Integer prodId=catDao.saveProduct(prod); [/b]
catDao.flush();
prod = catDao.findProductByCode(prodCode,srvId);
log4j.info("Name of product:" + prod.getProductName());
String prodName = "Product Worth Updating - Treo ";
prod.setProductName(prodName);
[b] catDao.saveProduct(prod); [/b]
assertTrue(prod.getProductName().equals(prodName));
assertEquals(prod.getProductId(),prodId);
log4j.info("Id of product updated:" + prodId);
}
The
Code:
saveProduct(prod)
method of my catalog Dao simply makes a call to
Code:
getHibernateTemplate().save(prod);
The 1st call to it generates an insert statement, which is what is expected.
However the 2nd call to it generates an update statement and I'm puzzled by this. I thought that if I wanted this behavior I'd have to use saveOrUpdate or replace the call to
Code:
getHibernateTemplate().save(prod);
by a call to
Code:
getHibernateTemplate().update(prod);
Can anyone explain this?