hybris items.xml 中使用index实现表的联合主键

SAP的hybris平台中,要定义一个表的主键比较简单,只要指定某个字段为unique即可。那么如果是复合主键呢?

在 items.xsd中是这么定义 unique的

<xs:attribute name="unique" type="xs:boolean" use="optional">
            <xs:annotation>
                <xs:documentation>If 'true', the value of this attribute has to be unique within all instances of this type. If there are multiple attributes marked as unique,

        then their combined values must be unique. Will not be evaluated at jalo layer, if you want to manage the attribute directly using jalo layer you have to               ensure uniqueness manually. Default is 'false'.

      </xs:documentation>
            </xs:annotation>
 </xs:attribute>

 

也就是说 联合主键可以通过 unique指定多个字段来达到要求。具体设置如下

<itemtype code="xxx" autocreate="true" generate="true" jaloclass="com.xxx.core.jalo.OrgSalesUnit">
                <deployment table="xxx" typecode="30001" />
                <attributes>
                    <attribute qualifier="code1" type="String" generate="true">
                        <persistence type="property"></persistence>
                        <modifiers read="true" write="true" search="true" optional="false" unique="true" />
                    </attribute>
                    <attribute qualifier="code2" type="String">
                        <modifiers read="true" write="true" search="true" optional="false" unique="true" />
                        <persistence type="property" />
                    </attribute>
</itemtype>

 

BUT 上面这么配置只会导致 code1 ,code2分别是unique的,并非code1+code2 为联合唯一,囧!

 

经测试,通过配置index 可以实现联合主键功能。配置如下,

 

<itemtype code="xxx" 

     <deployment table="xxx" typecode="30001" />
                <attributes>
                    <attribute qualifier="code1" type="String" generate="true">
                        <persistence type="property"></persistence>
                        <modifiers read="true" write="true" search="true" optional="false"  />
                    </attribute>
                    <attribute qualifier="code2" type="String">
                        <modifiers read="true" write="true" search="true" optional="false" />
                        <persistence type="property" />
                    </attribute>

          <indexes>
                    <index name="ProductSalesOrg" unique="true">
                        <key attribute="product"/>
                        <key attribute="salesOrg"/>
                    </index>
              </indexes>
</itemtype>

 

可通过impex导入数据进行测试


INSERT_UPDATE YourTableName;code1(code)[unique=true];code2(uid)[unique=true];
;000001;1234;
;000001;4321;

;000002;1234;
;000002;4321;

转载于:https://www.cnblogs.com/wahaha603/p/6877498.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值