SAP Hybris Service Layer, Build Process, Platform Question & Answer
Updated: May 12, 2020
What is the difference between modelService.create() and new operator?
Models in hybris can be created using any of the below two methods whereas the second one is preferred because. 1. New Operator - A.) UserModel userNew = new UserModel(); B.) new Operator is used mostly while writing test cases. c.) It is not attached to the context automatically, explicitly it is required to attached to the context. 2. ModelService Create method- A.) UserModel userModelService = modelService.create(UserModel.class); B.) Generate pk and assign it to User object (userModelService ). C.) userModelService will be assigned with the default values defined in the items.xml using initDefaultInterceptor. D.) modelService.saveAll() will automatically save userModelService model as it is automatically attached to the context.
Note- modelService.saveAll() should be used carefully. This will try to save all the models in the model context and if any error happens in previous save then the next save will also have the same issue. Rather modelService.saveAll(Collection models) is a good option.
How many ways an extension can be built in hybris?
What all files are generated after the platform build process or ant all target?
The Hybris Platform build process has been divided into the following phases.
2. Dependency Update
3. Build Extensions
An extension can be built either as a part of a platform build process or individually.
1. Platform build when you run the build from the platform all the extension defined in localextension.xml are built in a non-deterministic order. 2. Extension build This will build only the current extension in which ant build target is run. this step will skip bootstrapping and copying of build.xml file which was part of full platform build, resulting in some of the required parts of build framework missing.
In which order Hybris extensions are built during the platform build process?
The exact order in which extensions are build is non-deterministic (i.e exact order is not fixed) of the sequence defined in the config/localextension.xml. But any dependent extension is built only after all the required extensions are built. Required extensions for that particular extension are defined in the extensioninfo.xml file as below. So in the below code snippet cms2 and commerceservices are the dependent extensions and to be build before the current extension is built. <extension> ... <requires-extension name="cms2"/> <requires-extension name="commerceservices"/> ... </extension>