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

One-to-many relation - promotionResult can be made non-unique in the relation?

former_member981644
Participant
0 Likes
550

Hi,

In hybris, for one PromotionResult, you can have many PromomotionActions, as it is a one to many relation. But the relation defines PromotionResult as unique.

So, When the promotion is applied, the PromotionResult is saved through jalo layer, But if you try to clone the cfter the promotion is applied (it uses modelService.save()), its throws the following error bcz of uniqueness constraint in the relation.

[de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@6e185c4b]:**ambiguous unique keys {promotionResult=PromotionResultModel** ()} for model PromotionOrderEntryAdjustActionModel ()

Please confirm if promotionResult can be made non-unique in the relation?

Same kind of problem: https://experts.hybris.com/questions/5902/multiple-promotionresults-for-abstractpromotionact.html

Thanks, Chitra

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member981644
Participant
0 Likes

You are correct. Another Workaround is

The change is actually very minimal. The order of the following lines is reversed:

getModelService().saveAll(customer, orderModel); // FAILS HERE

// clear the promotionResults that where cloned from cart //PromotionService.transferPromotionsToOrder will copy them over //bellow. orderModel.setAllPromotionResults(Collections. emptySet());

...

The second line will clear the promotions and avoid the unique key violation. This is actually done anyway, we clear the promotions after cloning the order, they are then applied again. The issue here is that in some cases depending on the promotion result we run into this unique key violation when saving the order. The fix is simply to clear the promotions before saving.

// clear the promotionResults that where cloned from cart //PromotionService.transferPromotionsToOrder will copy them over //bellow. orderModel.setAllPromotionResults(Collections. emptySet());

getModelService().saveAll(customer, orderModel); // SAVES FINE ...

Former Member
0 Likes

Hello Chitra,

Thanks for the response. We tried the same and it worked but is these changes are suggestible because this is something provided Hybris OOTB and changing Hybris OOTB behavior may lead to some other unknown issue in application.

Thanks & Regards

Former Member
0 Likes

We are also facing similar kind of problem any solution to same.

former_member981644
Participant
0 Likes

Hi Anshul,

In promotion-items.xml the PromotionResult to PromotionAction relation is defined as follows. Yes, if we remove unique="true" field from sourceElement's modifiers tag than the problem seems to be resolved because UniqueAttributesInterceptor checks the uniqueness no longer (which is natural for a one to many relationships). But we do not know if it affects any other parts of the application hence we have to do proper testing.

Workaround:

    <modifiers read="true" write="true" initial="true" optional="true" search="true"/>





Regards, Chitra

Former Member
0 Likes

What is the business rationale behind cloning a cart containing promotions? Whats the use case here?

Ask a Question