在我当前的项目中,我需要处理一组包含一些财务信息的 XML 文件,然后对这些数据进行一些复杂的查询以填充数据库模式。
这些 XML 文件是基于 XSD 的,我使用 Hyperjaxb3 maven 插件从中生成 JPA 类,一切似乎都运行良好。不幸的是,我发现并发出问题,即使在 Hyperjaxb 文档、Google 和此处搜索了数小时后,我也无法找到解决方案。
这是一个 XML 文件的片段:
<metrics>
<metric name="pi1" type="decimal" periodType="instant" creationDate="">
<label xml:lang="es">Número de personal remunerado</label>
<label xml:lang="en">Number of staff recipient</label>
</metric>
<metric name="md2" type="monetary" periodType="duration" creationDate="">
<label xml:lang="es">Importe devengado en el período actual (flujo)</label>
<label xml:lang="en">Amount awarded in the current period (flow)</label>
</metric>
</metrics>
该问题与标签元素有关。其XSD定义如下:
<xs:element name="label">
<xs:complexType mixed="true">
<xs:attribute ref="xml:lang" use="required"/>
</xs:complexType>
</xs:element>
生成的 java 类如下所示:
@XmlRootElement(name = "label")
@Entity(name = "Label")
@Table(name = "LABEL")
@Inheritance(strategy = InheritanceType.JOINED)
public class Label implements Serializable, Equals, HashCode {
@XmlValue
protected String content;
...
@Basic
@Column(name = "CONTENT")
public String getContent() {
return content;
}
@Basic
@Column(name = "LANG")
public String getLang() {
return lang;
}
}
我的问题是,如何定义“内容”列的长度?目前,我一直在玩我的绑定文件
<jaxb:bindings node="//xs:element[@name='label']">
<hj:basic>
<orm:column length="1024"/>
</hj:basic>
</jaxb:bindings>
但完全没有区别。哦,顺便说一句,如果可能的话,应该避免对 XSD 文件进行更改,因为它是由第三方提供的。