Model service create method vs new operator - Hybris Interview question



ModelService is a Service provided by Hybris Out of the Box . It has many predefined methods such as create() , save () ,saveAll() .




When we try to create a new instances of an item type programmatically, there are two ways




1 . Using the Traditional new operator

2. or the hybris way, using the ModelService.create()




For Example

ProductModel product1 = new ProductModel();

ProductModel product2 = modelService.create(ProductModel.class);

The advantages of using model service method are below:
The model service create method will generate and assign the pk for product object.
The create method will initialize the default values, defined in items.xml for mandatory attributes.
While calling save all method, the object is already attached to context, and will be saved. While product1 needs to attach explicitly.



Flexible Search Query with JOIN Hybris Example


Hybris Composite Cron Job

Post a Comment