--Background on hybris Data Models
Data Models are defined in the <extension>-items.xml
file of each extension.;;;Essentially data entities (called "items" in hybris) are defined withitemtype elements, whereas relations between items are defined with relation elements.
The red classes in the diagram below show the files created for the Player itemtype incuppy-items.xml
.
The classes from which they are derived are shown in yellow.
The key point to bear in mind here is that many classes are generated from itemtypes and fall into three categories:
- Model classes created for use in the ServiceLayer where partners are encouraged to develop their business logic. Below, we will specify a new Itemtype Stadium, and hybris will generate several files including aStadiumModelJava class that we can use.
- Webservice-related classes which are created to support CRUD logic via RESTful URIs.These classes are only generated when the optional extension platformwebservices is included in your configuration.We will see how the Java classes StadiumDTO(s) and StadiumResoure(s) are used in the webservice trail step.
- Low-level Jalo classes. We will not address these classes as their use is discouraged.
--Add a dependency between CuppyTrail and Cuppy
1. Tell Eclipse that the Cuppytrail extension depends on the Cuppy extension: right click on cuppytrail - build path - configure build path
2. Tell the hybris build framework that the Cuppytrail extension depends on theCuppy extension. Open
cuppytrail/extensioninfo.xml
and add<requires-extension name="cuppy"/>
--Add Stadium to cuppytrail-items.xml
<itemtype code="Stadium" generate="true" autocreate="true"> <deployment table="CuppyTrailStadium" typecode="10123" /> <attributes> <attribute qualifier="code" type="java.lang.String" > <persistence type="property"/> <modifiers optional="false" unique="true"/> </attribute> <attribute qualifier="capacity" type="java.lang.Integer"> <description>Capacity</description> <persistence type="property" /> </attribute> </attributes> </itemtype>
You can check the used deployment typecodes in the hac http://localhost:9001/maintain/deploymentsKey points to note are that the code
itemtype code=Stadium generate=true autocreate=true
- defines a new type
Stadium
which implicitly extends fromGenericItem
autocreate=true
indicates thatStadium
is a new typegenerate=true
creates required sourcecode (not the model class) for the type
deployment table=CuppyTrailStadium typecode=10123
- specifies how the new type is mapped to the database
table
defines the database tabletypecode
is used internally e.g. to create item pks. Typecodes between 0 and 10000 are reserved by hybris. Nevertheless there are some exceptions
attribute qualifier=code type=java.lang.String
- creates a new attribute
code
by using the atomic typejava.lang.String
persistence type=property
- Defines how item are stored.
property
reflects the normal persistent behaviour
modifiers ... /
- advanced settings like read and write access
- defines a new type
-
--Relations
<relations> <relationcode="StadiumMatchRelation"localized="false"generate="true"autocreate="true"> <sourceElementtype="Stadium"qualifier="stadium"cardinality="one"/> <targetElementtype="Match"qualifier="matches"cardinality="many"/> </relation> </relations>
the relation is a one-to-many relation. which means that the mapping will be done by an additional column on the many side, i.e. the table
Match
--Enumtypes
<enumtypes> <enumtype code="StadiumType" autocreate="true" generate="true" dynamic="false"> <value code="openair"/> <value code="enclosed"/> </enumtype> <enumtype code="StadiumAccess" autocreate="true" generate="true" dynamic="true"> <value code="road"/> <value code="rail"/> <value code="plane"/> </enumtype> </enumtypes>
--Default values
<attribute type="StadiumType" qualifier="StadiumType"> <persistence type="property"/> <defaultvalue>em().getEnumerationValue("StadiumType","openair")</defaultvalue> </attribute>
--Updating the hybris System
Since we modified the hybris Data Model (by modifying an items.xml file), we must update the system, i.e. push the changes through to the database.
Select only the first checkbox: Update running system,
--Type system localization
-
Run all & updating systme[Update the system by selecting only Localize types]
type.stadiummatchrelationmatchescoll.name=StadiumMatchRelationMatchesColl type.stadiummatchrelationmatchescoll.description= ### Localization for type StadiumAccess type.stadiumaccess.name=StadiumAccess type.stadiumaccess.description= ### Localization for type StadiumType type.stadiumtype.name=StadiumType type.stadiumtype.description= ### Localization for type StadiumMatchRelation type.stadiummatchrelation.name=StadiumMatchRelation type.stadiummatchrelation.description= ### Localizationfor type Match type.match.stadium.name=Stadium type.match.stadium.description= ### Localizationfor type Stadium type.stadium.name=Stadium type.stadium.description= type.stadium.stadiumtype.name=Stadium type type.stadium.stadiumtype.description= type.stadium.capacity.name=Capacity type.stadium.capacity.description= type.stadium.code.name=Name type.stadium.code.description= type.stadium.matches.name=Matches type.stadium.matches.description= ### localizationfor enumvalues type.stadiumtype.openair.name=openair type.stadiumtype.enclosed.name=enclosed type.stadiumaccess.road.name=road type.stadiumaccess.rail.name=rail type.stadiumaccess.plane.name=plane
The easiest way is to do an export from hmc (Export Type Localizations)