在上面的代码中,我提到了部署表和类型代码。为什么
我们两个都用?
简短的回答是:这是因为它们的用途不同。
deployment table
使用deployment table,您可以将数据库表映射到itemtype。如果不提及deployment table,则itemtype的属性值将保存到其父itemtype的deployment table中;也就是说,在itemtype定义中没有deployment table的情况下,专利itemtype的数据库表将与itemtype进行映射。
如果您通过扩展GenericItem 创建itemtype,则必须声明deployment table(一种避免itemtype 的属性保存在GenericItem 表中的机制)。但是,如果您要扩展其他一些 itemtype,例如Product,您应该尽可能避免声明deployment table,以避免在执行灵活搜索查询期间需要太多的连接。
请注意,GenericItem 是 itemtype 的默认父级,即如果您未在 itemtype 定义中声明 extends...,则默认情况下,itemtype 将扩展 GenericItem,例如以下itemtype 定义将无法编译,因为DummyItem 默认扩展GenericItem,但没有提及deployment table。
<items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="items.xsd">
<itemtypes>
<itemtype code="DummyItem" autocreate="true">
<attributes>
<attribute qualifier="uname" type="java.lang.String">
<modifiers read="true" write="true" search="true" initial="true" optional="false"/>
<defaultvalue>"Hello"</defaultvalue>
<persistence type="property"></persistence>
</attribute>
</attributes>
</itemtype>
</itemtypes>
</items>
typecode
typecode 属性是引用该类型的唯一编号。 typecode 属性的值必须是介于0 和32767 (2^15-1) 之间的正整数,并且在整个hybris 应用程序中必须是唯一的,因为它是PK 生成机制的一部分,如下所示:
private static PK createPK_Counter(int typecode, long counter) {
if (typecode >= 0 && typecode <= 32767) {
//...
} else {
throw new IllegalArgumentException("illegal typecode : " + typecode + ", allowed range: 0-" + 32767);
}
}
查看this 和this 了解更多信息。