Reputation: 163
On my current project, I need to deal with a set of XML files containing some financial information and, later on, do some complex queries on that data in order to populate a database schema.
Those XML files are XSD based and I used Hyperjaxb3 maven plugin to generate JPA classes from it and everything seemed to be working fine. Unfortunately, I found and issue that I'm not able to find a solution for even after having spent plenty of hours searching in Hyperjaxb documentation, Google and here.
This is a fragment of an XML file:
<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>
The issue is related to the label element. Its XSD definition is as follows:
<xs:element name="label">
<xs:complexType mixed="true">
<xs:attribute ref="xml:lang" use="required"/>
</xs:complexType>
</xs:element>
And the generated java class looks like this:
@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;
}
}
My question is, how can I define the length of that "content" column? At the moment, I've been playing around with my bindings file
<jaxb:bindings node="//xs:element[@name='label']">
<hj:basic>
<orm:column length="1024"/>
</hj:basic>
</jaxb:bindings>
but made no difference at all. Oh, by the way, if possible, making changes to the XSD file should be avoided as it is provided by a third party.
Upvotes: 2
Views: 367
Reputation: 43709
Ok, as promised, here's the answer.
Disclaimer: I'm the author.
Consider the sample XSD as you've proposed:
<xs:element name="ten">
<xs:complexType mixed="true">
<xs:attribute name="label" type="xs:string"/>
</xs:complexType>
</xs:element>
I've figured out that customizes the content property:
<jaxb:bindings node="xs:element[@name='ten']/xs:complexType">
<hj:basic name="content">
<orm:column length="1024"/>
</hj:basic>
</jaxb:bindings>
But the problem seems to be that XJC applies this customization BOTH to the class as well as property. That customization is not acknowledged on the class. And since XJC is very strict about this, it failes with 0.6.0
.
I've added a fix for this in 0.6.1
, but it's not released yet, so you'll have to check out and build on your own for now, until 0.6.1 is released (no plan for that yet).
ps. You might find this tutorial on pull requests helpful. You did the change in your repo but did not actually send me a PR.
Upvotes: 1