I have service method call createProduct():
Code:
public void createProduct()
{
Product product1 = new Product();
//set product1 attributes
session.save(product1);
}
Another service method call listProducts():
Code:
public List<Product> listProducts()
{
Criteria criteria = session.createCriteria(Product.class).
//return all products
List productList = criteria.list();
return productList;
}
The above 2 service calls are made in the same transaction context. i.e. first create the product and get a listing of products.
The problem is, productList listing contains "product1" instance in memory(created from createProduct()) instead of reading corresponding row from DB.
The same happens when a product is edited and then the DB is queried. The query contains the edited object in memory.
How can this happen ? Has anyone encountered this situation. How do I solve this problem.
Note:- I'm using Spring's declarative transaction management. I'm also using OpenSessionViewFilter. Therefore FLUSH_MODE = NEVER.
Any help is appreciated.