Как создать составной уникальный ключ в Hybris - PullRequest
0 голосов
/ 06 апреля 2020

Можно ли создать составной уникальный ключ в Hybris с помощью предметов. xml?

В данном примере:

        <itemtype  code="SimpleDevice">
            <deployment table="simpleDevice" typecode="20063"/>
            <attributes>
                <attribute qualifier="productId" type="java.lang.String">
                    <persistence type="property" />
                    <modifiers unique="true" optional="false" initial="true"/>
                    <description>Device's product ID</description>
                </attribute>
                <attribute qualifier="serialNumber" type="java.lang.String">
                    <persistence type="property" />
                    <modifiers unique="true" optional="false" initial="true"/>
                    <description>Device's serial number</description>
                </attribute>
            </attributes>
        </itemtype>

Как мне объединить атрибут 2, чтобы они вели себя как составной уникальный ключ? Мой план B состоит в том, чтобы использовать некоторый перехватчик, чтобы проверить, существует ли такая комбинация перед ее созданием. Но я хочу избежать перегрузки БД при импорте нескольких элементов Impex.

Ответы [ 2 ]

2 голосов
/ 06 апреля 2020

Вам необходимо добавить новый уникальный индекс в элемент indexes для совместного использования нескольких атрибутов в индексе.

<itemtype  code="SimpleDevice">
    <deployment table="simpleDevice" typecode="20063"/>
    <attributes>
        <attribute qualifier="productId" type="java.lang.String">
            <persistence type="property" />
            <modifiers unique="true" optional="false" initial="true"/>
            <description>Device's product ID</description>
        </attribute>
        <attribute qualifier="serialNumber" type="java.lang.String">
            <persistence type="property" />
            <modifiers unique="true" optional="false" initial="true"/>
            <description>Device's serial number</description>
        </attribute>
    </attributes>
    <indexes>
        <index name="SimpleDeviceIdx" unique="true">
            <key attribute="productId" />
            <key attribute="serialNumber" />
        </index>
    </indexes>  
</itemtype>
1 голос
/ 06 апреля 2020

Данный пример уже верен. Это делает комбинацию productId и serialNumber уникальной.

...