Adding a New Model

Follow the steps to learn how to generate ServiceLayer models.

Prerequisites

In this example, you need to prepare an extension in a certain way. For details, see Preparing an Extension for ServiceLayer Examples. If you have completed other procedures of the ServiceLayer documentation, you should already have this extension prepared.

Context

ServiceLayer models are generated based on SAP Commerce item types. Therefore, to generate a new model, first define a new SAP Commerce item type.

To illustrate how to add a new model to SAP Commerce, we define the new item type: ContactRequest.

Procedure

  1. Define the ContactRequest.
    <itemtype generate="true"
       code="ContactRequest"
       jaloclass="org.training.jalo.ContactRequest"
       extends="GenericItem"
       autocreate="true">
    	<deployment table="UserRights" typecode="32767"/>
    	<attributes>
    		<attribute qualifier="message" type="java.lang.String">
    			<description>Message</description>
    			<modifiers initial="true"/>
    			<persistence type="property"/>
    		</attribute>
    		<attribute qualifier="sender" type="java.lang.String">
    			<description>Sender</description>
    			<modifiers initial="true"/>
    			<persistence type="property"/>
    		</attribute>
    	</attributes>
    </itemtype>

    Types in SAP Commerce are defined in the extension's items.xml file. It is highly recommended that you specify a deployment for a GenericItem subtype, otherwise the instances of that subtype are stored in the same table as instances of GenericItem.

  2. Generate the model.
    • If you use Eclipse, the generation process is automatically started when you save the items.xml file (the default Eclipse project is shipped with an Eclipse build launcher) and will refresh the gensrc directory of your extension as well as the bootstrap/gensrc directory of the platform.

    • If you do not use Eclipse, trigger the generation process manually by building SAP Commerce:

      • Open a command shell.

      • Navigate to the <HYBRIS_BIN_DIR> /platform directory.

      • Make sure that a compliant Apache Ant version is used:

        • On Windows systems, call the <HYBRIS_BIN_DIR> /platform/setantenv.bat file. Do not close the command shell after this call as the settings are transient and would get lost if the command shell is closed.

        • On Unix systems, call the <HYBRIS_BIN_DIR> /platform/setantenv.sh file, such as: . ./setantenv.sh

      • Call ant clean all to build SAP Commerce.

  3. Find the new model in the bootstrap/gensrc folder.

    The build framework generates a model class for you, org.training.model.ContactRequestModel.