Data Modelling in Hybris

  • Hybris data modelling helps an organisation in maintaining their database and helps to manage database connections and queries.
  • Data models in SAP Commerce are defined via items.xml file in each extensions. The core-items.xml contains the basic data models and relations which are used like users, products, orders etc.
Hybris has following types supported for data modelling:-
  • Atomic Types :- Used to create various Atomic Types.
  • Collection Types :- Used to create various Collection.
  • Enum Types :- Used to define Enums(means fixed value eg: week days, name of month).
  • Map Types :- Used to define maps.
  • Relation Types :- Used to create relation between the tables.
  • Item Types :- Used to create tables.
Note :- Above all types are in a order in which they are declared in items.xml.

Now let discuss all the types briefly.

Item Type:-

Item types are basic ones which are used to create new tables or to extend existing tables like products, customers to add our own attribute.

  • Define the new item type without extending any existing item type.
  • autocreate=”true” :- This indicates that ProductTimeCronJob is a new item type and new database entry for this type will be created. We should set it to true for the first definition of item type.
  • generate=”true” :- By this Java class files will be generated for the item type. Set the generate modifier to false results in no java class file being generated for this type.
  • deployment table :- Items within SAP Commerce are made persistent by writing values into a database. Within the database, the values are stored in tables. Deployment table modifier is to specifies the table where the instances of the item type are stored. This is given for new item type only not for existing item type.
  • typecode :- It is used to create item type PKs. Using typecode which already exists will cause failure.
  • attribute :- In Hybris the properties of an item type are known as attributes. The attribute itself could be of primitive type (like String or integer) or it could be of type like that of any other item type.
  • modifiers for attributes :- read = true – means attribute is readable and getter method will be generated for the attribute. If, false we cannot access it from our java program.
  • write = true :- means attribute is writable and setter method will be generated for the attribute. If false, we cannot modify the value.
  • optional = true :- if false, it is mandatory to initialize this attribute.
  • search = true :- the attribute is searchable through Flexible Search queries.
Persistent type for attribute:-

It is one of the property of item type attribute which can be set as ( Dynamic or Property ).

  • Property:- if it is set as property, it means the value will be stored at DB.
  • Dynamic:- if it is set as dynamic, it means that the value will not be the part of database table. It is just calculated at run time.
  • Define the new attribute to the existing item type:-

Here autocreate and generate is set as “false” as it’s not new item type. This way we can add new attributes to the existing item type.

  • Define the new item type by extending it with the existing item type:-

jalo Class:- It is used to combine both data model and business logic or to write business logic.

Atomic Type:-

These are defined as basic types in Hybris, which include Java number and string objects- java.lang.integer, java.lang.boolean, java.lang.string, java.lang.float etc. The item types which are primitive in Java are called Atomic item type.

Collection Type:-

Used for creating collections for similar item types.

Enum Types:-

Used to build enumeration in Java for preparing particular set of values. The group of fixed constants are defined as enums.

Map Types:-

Map types are used to store the key value pairs in SAP Commerce (Hybris).

Relation Types:-

These are used to define relations between the two tables.

Leave a comment