cancel
Showing results for 
Search instead for 
Did you mean: 

getting Exception while saving Customer model

Former Member
0 Kudos

Hi Expert, I am loading the model first. final CustomerModel customerModel = getModelService().get(CustomerModel.class);

Then i am updating one attribute in customer model and then performing

             **modelService.save(customerModel);**

Then i am getting the below exception. Could you please help.

ion is de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@4e5db93c]:missing values for [uid] in model CustomerModel () to create a new Customer] with root cause de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator@4e5db93c]:missing values for [uid] in model CustomerModel () to create a new Customer at de.hybris.platform.servicelayer.interceptor.impl.MandatoryAttributesValidator.onValidate(MandatoryAttributesValidator.java:98) at de.hybris.platform.servicelayer.internal.model.impl.wrapper.ModelWrapper.invokeValidateInterceptors(ModelWrapper.java:291) 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:58) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.performPersistenceOperations(DefaultModelService.java:711) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAllInternal(DefaultModelService.java:706) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.saveAll(DefaultModelService.java:686) at de.hybris.platform.servicelayer.internal.model.impl.DefaultModelService.save(DefaultModelService.java:634) at com.batelco.b2ctelco.storefront.controllers.pages.HomePageController.home(HomePageController.java:88) at sun.reflect.Na

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi ,

The following code does NOT give the model you want to update.

  final CustomerModel customerModel = getModelService().get(CustomerModel.class);

This just returns you a new instance of CustomerModel.class. Now if you don't set UID for this customer and save,you get an exception saying "mandatory attribute uid is missing". If you do set the uid,you get another exception "duplicate uid" because it already exists.

Basically, you are not really updating an existing customer,rather creating a new one.

If you want to update an existing customer, you either need to get the correct customer by using Flexible Search Query.

Alternatively you can also use 'model by example' option as below:

 CustomerModel example = new CustomerModel();
 example.setUid(".mahato@www.com");
 
 CustomerModel  = flexibleSearchService.getModelByExample(example);
 .. 
 ..
 
 modelService.save();

Hope this helps.

Best

Shanmugaraja

Former Member
0 Kudos

Thanks its works for me.. i was doing wrong.

Answers (4)

Answers (4)

Former Member
0 Kudos

From the code snippet you posted, It doesn't look like you are loading the customer model you expect, why don't you give the get method the pk? or an instance of a customer, you seem to be creating a new one, you then set some attributes missing others that are mandatory, and then when you set the uid (mandatory) you are again violating a unique constraint, load the customer properly, make the changes you want to make then save it.

Former Member
0 Kudos

Thanks yes i got your point

Former Member
0 Kudos

UID is the value which identifies your customer, and must be specified for each new user, commonly, email is used as uid

Former Member
0 Kudos

Yes , i am aware but when i am not setting the UId getting one exception , if i set the UID another Exception. That is the point.

Former Member
0 Kudos

i want to update one attribute for the same customer and need to save.

Former Member
0 Kudos

I hope you are aware that UID is unique.

Former Member
0 Kudos

Yes , i am aware but when i am not setting the UId geeting one exception , if i set the UID another Exception. That is the point.

Former Member
0 Kudos

Could you please let us which exception you are getting while updating with UID. Since UID is mandatory for CustomerModel, without UID you cannot save it using modelService.

Former Member
0 Kudos

when i set UID explicit customerModel.setUid(UID) . I am getting another Exception; exception is de.hybris.platform.servicelayer.exceptions.ModelSavingException: [de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@8093d38]:ambiguous unique keys {uid=.mahato@www.com} for model CustomerModel () - found 1 item(s) using the same keys] with root cause de.hybris.platform.servicelayer.interceptor.InterceptorException: [de.hybris.platform.servicelayer.interceptor.impl.UniqueAttributesInterceptor@8093d38]:ambiguous unique keys {uid=.mahato@www..com} for model CustomerModel () - found 1 item(s) using the same keys