1

I am trying to use hyperjaxb3 to create a relational schema from the three .xsd (C14054.xsd, C14054CodeLists.xsd & C14054DataTypes.xsd) available here and then marshal data from XML <-> Java <-> Relational.

hyperjaxb3 has already done a better job of creating the relational schema than a very expensive commercial tool I evaluated - but I can't quite get it to do what I want with Enums.

e.g. in C14054.xsd, the 'Provider' element references 'RECID'

<xs:element name="Provider">
<xs:complexType>
  <xs:sequence>
    <xs:element ref="RECID" minOccurs="1" maxOccurs="1" />

which in turn is of TYPE 'RECIDCodeType'

<xs:element name="RECID" type="RECIDCodeType" />

from C14054CodeLists.xsd

<xs:complexType name="RECIDCodeType">
<xs:simpleContent>
  <xs:extension base="RECIDCodeContentType" />
</xs:simpleContent>

which extends 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>

  1. Enumerated types are created in the database as 'lookup tables' with the columns 'HJID' and 'VALUE_'. Is it possible for the Primary Key of the table to be VALUE_, rather than the autonumber HJID?

I.e. can the only valid entry (at the database tier) into Provider.RECID (I changed the column name in bindings.xjb) be '14054'?

  1. Is it possible for the Enum values to be persisted into the relation tables when the schema is created?

I.e. can 14054 be added as a row to the Subpurposecodetype.VALUE_ column in the database?

Many thanks for any light anybody can shed!

pieman
  • 26
  • 3
  • I don't have time for the full answer at the moment, but here are the hints. (1) You basically want to use the value as id. This should be possible with the `hj:id` customization. Must be placed on the value property - I think attached to `xs:simpleContent`. (2) Initializing the database isn't in scope. You'll have to do custom DDL scripts on your own for this. – lexicore Jul 22 '15 at 10:22
  • lexicore - you are truly a king amongst men! – pieman Jul 23 '15 at 12:40
  • 1) I thought I had tried every possible location of that might work - but apparently not! Your assurance that it was possible was what I needed to have another crack and get it! I'll post the full answers below. 2) No worries. We are provided with .csv files of the enumeration / lookup values too, so it is not a big deal to populate the generated schema. But if you ever want to add it to a future version of hyperjaxb... ;) Thanks so much! hyperjaxb is going to save us a lot of time. Does the project take donations? – pieman Jul 23 '15 at 12:51

1 Answers1

0

Hopefully, this will help some other people in the future (thanks lexicore for pointing me in the right direction!):

Inline solution:

<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>

External bindings file solution:

<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>

Result:

@Id
@Column(name = "VALUE_")
public String getValue() {
    return value;
}
pieman
  • 26
  • 3