Hi there,
Can someone please help resolve this error? I am trying to update in hibernate but transaction fails with the error "Illegal attempt to associate a collection with two open sessions". I am using Hibernate with Spring. I am using HibernateTemplate for the transactions. I have a simple form with Product information entry. In my controller, I read entries in form and then attempt to update. However, this fails with above mentioned error. In my controller, I have following code -
Code:
Product product = this.productService.findByProductId(productId);
Product commandProduct= (Product) command; //command object
product.setProductType(commandProduct.getProductType());
product.setProductDescription(commandProduct.getProductDescription());
this.productService.update(product);
As you can see above, commandProduct contains data from the form in GUI and based on the product id that is open, I load the product object, set values of some of the fields that were changed in GUI and then try to call update. The service method makes a simple call -
Code:
getSession().update(product);
but above update statement fails with the error "Illegal attempt to associate a collection with two open sessions". When I try merge instead of update, then I don't get any errors but it does not update anything.
What am I doing wrong and how to correct this issue? Can any guru help?