我正在尝试使用 hyperjaxb3 从三个 .xsd(C14054.xsd、C14054CodeLists.xsd 和 C14054DataTypes.xsd)available here 创建关系架构然后从 XML <-> Java <-> Relational 编码数据。
hyperjaxb3 在创建关系模式方面已经比我评估过的非常昂贵的商业工具做得更好 - 但我不能完全让它用 Enums 做我想要的事情。
例如在 C14054.xsd 中,“Provider”元素引用“RECID”
<xs:element name="Provider">
<xs:complexType>
<xs:sequence>
<xs:element ref="RECID" minOccurs="1" maxOccurs="1" />
其类型为“RECIDCodeType”
<xs:element name="RECID" type="RECIDCodeType" />
来自 C14054CodeLists.xsd
<xs:complexType name="RECIDCodeType">
<xs:simpleContent>
<xs:extension base="RECIDCodeContentType" />
</xs:simpleContent>
它扩展了 RECIDCodeContentType
<xs:simpleType name="RECIDCodeContentType">
<xs:restriction base="xs:string">
<xs:enumeration value="14054">
<xs:annotation>
<xs:documentation>
<Label>2014/15 AP student record</Label>
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
- 枚举类型在数据库中创建为“查找表”,其中包含“HJID”和“VALUE_”列。表的主键是否可以是 VALUE_,而不是自动编号 HJID?
即Provider.RECID(我更改了 bindings.xjb 中的列名称)的唯一有效条目(在数据库层)可以是“14054”吗?
- 创建架构时是否可以将枚举值保留到关系表中?
即14054 可以作为一行添加到数据库中的 Sub Purposecodetype.VALUE_ 列吗?
非常感谢任何人都能提供的任何帮助!
最佳答案
希望这能在未来帮助其他人(感谢 lexicore 为我指明了正确的方向!):
内联解决方案:
<xs:simpleType name="RECIDCodeContentType">
<xs:annotation>
<xs:appinfo>
<hj:id />
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="14054">
<xs:annotation>
<xs:documentation>
<Label>2014/15 AP student record</Label>
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
外部绑定(bind)文件解决方案:
<jaxb:bindings schemaLocation="C14054CodeLists.xsd" node="/xs:schema">
<!-- RECIDCodeType : Make VALUE Primary Key -->
<jaxb:bindings node="xs:simpleType[@name='RECIDCodeContentType']">
<hj:id />
</jaxb:bindings>
</jaxb:bindings>
结果:
@Id
@Column(name = "VALUE_")
public String getValue() {
return value;
}
关于java - hyperjaxb3 : Enumeration questions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31519715/