ModelService.Refresh() method and Its uses

The OOB Hybris Model Service provides a method, to refresh the model. Usually we use this method to refresh the data, before saving the data in database, using save method.
There might be conditions, where some other thread or operation would be updating the same model instance. By doing a refresh, we can be sure of not loosing those changes. This is of more importance, if we are going through a time consuming transaction like payment.
Also transaction like, stock update, may happen simultaneously from multiple users, so we should always refresh the model, before saving it.

Composite Cron Job in Hybris

Composite Cron Job : 

1. A composite cronJob is a composition of multiple cronjobs .

2. It means that a cronjob will call another job and also multiple cronjobs successively.

3. This phenomena is driven by CompositeCronJob and CompositeEntry.

How to make Extension as Template in Hybris

1.Change in extensioninfo.xml file 

First add the property below in the extensioninfo.xml after core tag of  the extension which you want to use as a template.

Eg. We want to make electronicstore as template. Add he below property in extensioninfo.xml of  electronicstore.

<meta key=”extgen-template-extension” value=”true”/>

2. Create an file .

Create  a blank file named as parallel to file in your extension.

We will create an file in electronic store 

3. Modify file .

Modify file with below properties :


4. Do Ant extgen .

Go to your platform directory .
Type setantenv.bat 
Type ant extgen .
You will see your extension in templates.

Create a new extension in Hybris

To create an extension we will use ant extgen command and yempty template .

1. Go to platform directory .
2. Run setantenv.bat commad.
3. Run ant extgen
4. Extgen prompts you to enter extension name . Enter extension name and press Enter.
5. Enter package name as desired .
6. New Extension will be created in custom folder in your hybris /bin directory.

7. Add Extension name to localExtensions.xml.

8. Run ant clean all.

Difference between ant all and ant clean all in hybris

ant clean all
ant all
 Delete all model classes create again.
Does not delete model classes but create new ones if required.
It checks whether config,log,data,temp etc folders are available inside hybris folder.
If this folder structure is not available then it creates the folder structure
It assumes folder structure is already exist
 If there is no build, It will create a build from scratch, if there is any build exist, It will delete and recreate it
If there is no build, it will create a build from scratch, if there is any build exist, it will modify it rather than recreating it.
Slower than ant all as it delete classes and folders and regenerate them.
Faster than ant clean all
Is advised to use only when there are changes in items.xml file
Is advised to use for every build.

How to run multiple hybris instance in one machine?

So many times you need you run more than 1 server of hybris on same machine , like if you want to run your customized code and OOTB Hybris Store as well . You just need to add the following properties in File.

Then do ant all and start the hybris server :



tomcat.debugjavaoptions=-XXaltjvm=dcevm -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=6001,suspend=n

This will help you to run hybris server in debug mode as well on port 6001

How can you add values to a collection type attribute and Map from Impex in Hybris ?

1. For Collection type attribute you can use comma separated values which are to be inserted.

eg. INSERT_UPDATE UserGroup;uid[unique=true];groups(uid)[mode=append];readableLanguages(isocode);writeableLanguages(isocode);

Here , both readableLanguages and writeableLanguages are of type LanguageCollection .

2. Also you can use mode=append in header for Collection Type attribute .

3. For Map type attribute by default you have to use -> delimiter within key and value pair .

INSERT_UPDATE myProduct;myAttribute

How to make cronjob run on some servers(in case of load balancer or cluster ) and but not on others?

This scenario can be achieved using Nodes concept in hybris.

1. First you need to define applicable nodes in using cluster.node.groups property such as

cluster.node.groups = backoffice,storefront .

2. Assign the cronjob to group of nodes by 2 ways :

 a) When you define the cronjob then use method .setNodeGroup("nameofnodegroup") like .setNodeGroup("storefront ").

b) Using Impex :

INSERT_UPDATE CronJob; code[unique=true];job(code);nodeGroup

Whenever next time the cronjob is going to it will trigger on the nodeGroup defined .

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.

Play Video File Android Example

Now, Moving forward in Android Examples ,Today you are going to learn a new Android Example of Play Video File Android Example with code . If you are a beginner Please go through the tutorial from very start from here .Play Video File in Android is very simple and easy to code .You can also incorporate  Play Video File Android Example in your project or app. For Play Video File Android Example ,we used Android Studio you can use any other Android IDE as well.

Play Video File Android Example
Play Video File Android Example

Steps of Play Video File Android Example are  explained below :

Step 1 : Create a new Project -PlayVideo and Activity 

Play Video File Android Example
Play Video File Android Example

Step 2 : Create Activity xml 
Add a button and Video View in activity xml file for Play Video File Android Example with code.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="" 
         android:layout_height="fill_parent"    >

    <Button android:id="@+id/button"
        android:text="PLAY Video"        />

         android:layout_height="wrap_content"        />


Step 3 : Project Structure

For Play Video File You need to place a video file ,as I placed test.mp4 file under raw directory as shown below :

Play Video File Android Example
Play Video File Android Example

Step 4 : Create Java Activity

import android.os.Environment;
import android.os.Bundle;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

public class PlayVideoActivity extends Activity implements SurfaceHolder.Callback{

    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean pausing = false;;

    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {

        Button buttonPlayVideo = (Button)findViewById(;


        //Displays a video file.        VideoView mVideoView = (VideoView)findViewById(;

        Uri uri = Uri.parse("android.resource://"+R.raw.test);


        buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

            @Override            public void onClick(View v) {

                // VideoView refference see main.xml                VideoView mVideoView = (VideoView)findViewById(;

                Uri uri = Uri.parse("android.resource://");


    @Override    public void surfaceChanged(SurfaceHolder holder, int format, int width,
                               int height) {
        // TODO Auto-generated method stub

    @Override    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub

    @Override    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub