cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Ambiguous Key Error for CartEntry on Cart recalculation

sbsamuell
Explorer
0 Likes
382

Hi all,

I have a cronjob responsible to take some information related to Carts in my project.

Before taking this data I need to make the cronjob recalculates the Carts in order to avoid taking expired promotions or old data of the carts.

I'm using the standard recalculate Service to make the recalculation of the cart:

final CommerceCartParameter parameter = new CommerceCartParameter();
parameter.setEnableHooks(true);
parameter.setCart(cart);getCommerceCartService().recalculateCart(parameter);

It usually works fine, however for a specific combination of promotions into the cart I have an exception that I'm trying to understand the reason and I still couldn't, and I would like to know if someone can help me.

The combination is:

The cart has 2 or more Buy X get Y Free + (Applied) And has An Order Threshold (with gift) also applied.

The exception is:

de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@7f386682]:ambiguous unique keys {entryNumber=5, order=CartModel (8837380735019@377)} for model CartEntryModel (8815623569452@3) - found 1 item(s) using the same keys
	at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:302)
	at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.validate(ModelWrapper.java:239)
	at de.hybris.platform.servicelayer.internal.model.extractor.impl.DefaultModelExtractor.process(DefaultModelExtractor.java:57)
	at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.performPersistenceOperations(DefaultModelService.java:720)
	at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:715)
	at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:695)
	at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:643)
	at de.hybris.platform.promotionengineservices.action.impl.DefaultAddProductToCartActionStrategy.normalizeEntryNumbers(DefaultAddProductToCartActionStrategy.java:232)
	at de.hybris.platform.promotionengineservices.action.impl.DefaultAddProductToCartActionStrategy.undo(DefaultAddProductToCartActionStrategy.java:211)
	at de.hybris.platform.promotionengineservices.action.impl.DefaultAddProductToCartActionStrategy$$FastClassBySpringCGLIB$$1.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:737)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:672)
	at de.hybris.platform.promotionengineservices.action.impl.DefaultAddProductToCartActionStrategy$$EnhancerBySpringCGLIB$$1.undo(<generated>)
	at de.hybris.platform.promotionengineservices.promotionengine.impl.DefaultPromotionEngineService.undoPromotionAction(DefaultPromotionEngineService.java:479)
	at de.hybris.platform.promotionengineservices.promotionengine.impl.DefaultPromotionEngineService.cleanupAbstractOrder(DefaultPromotionEngineService.java:462)
	at de.hybris.platform.promotionengineservices.promotionengine.impl.DefaultPromotionEngineService.updatePromotionsNotThreadSafe(DefaultPromotionEngineService.java:369)
	at de.hybris.platform.promotionengineservices.promotionengine.impl.DefaultPromotionEngineService.updatePromotions(DefaultPromotionEngineService.java:408)
	at de.hybris.platform.commerceservices.order.impl.DefaultCommerceCartCalculationStrategy.recalculateCart(DefaultCommerceCartCalculationStrategy.java:148)
	at de.hybris.platform.commerceservices.order.impl.DefaultCommerceCartService.recalculateCart(DefaultCommerceCartService.java:193)
...............

The weirdest part is that, for example, when updating an entry at the store, which demands a cart recalculation the problem doesn't happen.

It's happening only when I try to recalculate it using a cronjob.

I debugged for example both the recalculate flows, when updating the cart at the store and the flow for the cronjob, and both do exactly the same thing into the method where the problem happens (DefaultAddProductToCartActionStrategy.normalizeEntryNumbers), however for the store action it doesn't produce an exception and for the cronjob, it happens.

I appreciate it if someone helps me with that.

Thanks!

Accepted Solutions (0)

Answers (0)

Ask a Question