on ‎2019 Mar 29 7:41 AM
Hi guys,
I am new to hybris development, and I have created a custom extension in my hybris. I don't really understand how to use an existing service to persist my Customer data to the database.
I have tried using the ModelService, but i do not know how to initialize it.
It would be great if anyone can help me understand how data can be persisted in Hybris Commerce.
Thank You,
Request clarification before answering.
Hi All,
I solved my issue, to initialize the modelService, we can use the code below. Also if we are performing CRUD operations, we need to provide the Uid of the model, before save().
final ModelService modelService = Registry.getApplicationContext().getBean("modelService", ModelService.class);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you added the dependency in spring.xml file?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi - you need to inject ModelService as shown below:
@Resource
private ModelService modelService;
and then after setting the values in your model object, you need to save the model using modelService.save(your-model-object)
If you still get NPE, please inject ModelService as given below:
@Autowired
private ModelService modelService;
and use the following in your Spring Configuration file:
<context:annotation-config/>
<context:component-scan base-package="your-package-name"/>
You can find many examples in Test classes. A File Search in ee with the parameters as given in the screenshot will return the classes you can refer for your requirement.

You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you try injecting ModelService as given below?
@Autowired
private ModelService modelService;
No. This problem is becauseDo i need to maintain dependencies in my extension dependency.xml if I am using CustomerModel? Maybe there is a runtime error occuring because of this?
ModelService is not getting instantiated.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 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.