on 08-16-2017 10:48 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
UID is the value which identifies your customer, and must be specified for each new user, commonly, email is used as uid
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope you are aware that UID is unique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.