Skip to Content
0
Former Member
Jan 15, 2015 at 11:10 AM

Update product with modelService.save() fails

1124 Views

Hi there,

I implemented my own facade layer to manage the products in hybris. At the time I was able to create and to receive products, but unfortunately I can't update products...

If I try to update a product with modelService.save() method, I receive the following error message:

 SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [/storefront] threw exception [Request processing failed; nested exception is de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@6cd408b1]:ambiguous unique keys {catalogVersion=CatalogVersionModel (8796093284953), code=99432499} for model ProductModel (<unsaved>) - found 1 item(s) using the same keys] with root cause
 de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@6cd408b1]:ambiguous unique keys {catalogVersion=CatalogVersionModel (8796093284953), code=99432499} for model ProductModel (<unsaved>) - found 1 item(s) using the same keys
     at de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor.onValidate(UniqueAttributesInterceptor.java:159)
     at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:272)
     at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.validate(ModelWrapper.java:216)

It looks like modelService was trying to create a new product instead of updating a product...

The implementation looks like that:

 final ProductModel productModel = productService.getProductForCode(product.getCode());
 
 productModel.setManufacturerAID(product.getManufacturerAID());
 productModel.setDescription(product.getDescription());
 productModel.setApprovalStatus(checkApprovalStatus(product.getApprovalStatus()));
 productModel.setCatalogVersion(catalogVersionService.getCatalogVersion(product.getCatalogName(), product.getCatalogVersion()));
 
 modelService.save(productModel)

Does anybody an idea how to solve this problem?

greetz