Day 4: Composite Unique Keys in Hybris
You know until now I thought that composite unique keys are formed just by including unique=true for multiple attributes. My ignorance amazes me.
To define composite unique keys, we need to add new unique index in indexes element.
Consider this category table. Category code along with the catalogVersion makes the primary key.
<itemtype code="Category"
generate="true"
jaloclass="de.hybris.platform.category.jalo.Category"
extends="GenericItem"
autocreate="true">
<deployment table="Categories" typecode="142"/>
............
...............
<indexes>
<index name="codeIDX" unique="false">
<key attribute="code"/>
</index>
<index name="versionIDX" unique="false">
<key attribute="catalogVersion"/>
</index>
<index name="codeVersionIDX" unique="true">
<key attribute="code"/>
<key attribute="catalogVersion"/>
</index>
</indexes>
</itemtype>
I have always felt proud about my data modeling knowledge. Now looking back, I shudder at my level of ignorance.