Sap 如何在Hybris中创建复合唯一密钥

Sap 如何在Hybris中创建复合唯一密钥,sap,hybris,unique-key,Sap,Hybris,Unique Key,是否可以通过items.xml在Hybris中创建复合唯一键 在给定的示例中: <itemtype code="SimpleDevice"> <deployment table="simpleDevice" typecode="20063"/> <attributes> <attribute qualifier="productId" type="java.

是否可以通过items.xml在Hybris中创建复合唯一键

在给定的示例中:

        <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>

设备的产品ID
设备的序列号

如何组合2属性以使其表现为复合唯一键?我的计划B是在创建之前使用一些拦截器来检查这样的组合是否已经存在。但我希望在通过Impex导入多个项目时避免数据库过载

给定的示例已经是正确的。它使productId和serialNumber的组合唯一。

您需要在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>

设备的产品ID
设备的序列号

Hi。对于给定的示例,我无法插入Product:1-SerialNumber:1和Product1-SerialNumber2。因为在第二个例子中,我已经有了Product=1。阻止我将其与其他序列号组合一起使用。@RicardoMachado我对其进行了测试,并且成功了:我在创建平台后创建了记录Initialize@RicardoMachado是正确的,给定的示例按属性创建单独的唯一索引。在Hybris中,如果声明多个唯一键,则其行为类似于复合唯一键。因此,你提到的只是正确的。这很有趣。里卡多的代码使用内存数据库工作。我还没有使用像mySQL这样的数据库进行测试。我是否仍应该保留“否”,因为修饰符分别使每个属性都是唯一的。