1

I read this link about fetchtype in hyperjaxb. From the looks of it, it seems that one can only add a simpleType fetch-type to the xsd file and then add a fetch attribute to every complexType.

How would someone customize the following xsd fragment so that the resulting java method at bottom below would have a fetchtype=lazy annotation?

<xs:complexType name="SomeTypeName">
    <xs:sequence>
        <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="someCode1" type="Code" minOccurs="0"/>
        <xs:element name="someCode2" type="Code" minOccurs="0"/>
        <xs:element name="someCode3" type="Code" minOccurs="0"/>
        <xs:element name="someCode4" type="Code" minOccurs="0"/>
        <xs:element name="someCode5" type="Code" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="Code">
    <!--<xs:sequence>elements with nested data types omitted for simplicity</xs:sequence>-->
    <xs:attribute name="code" type="xs:string" use="optional"></xs:attribute>
    <xs:attribute name="Name" type="xs:string" use="optional"></xs:attribute>
</xs:complexType>

Here is the Java property that should say fetchtype=lazy:

@ManyToOne(targetEntity = Code.class, cascade = {
    CascadeType.ALL
})
@JoinColumn(name = "SOME_CODE1_P_0")
public Code getSomeCode1() {
    return someCode1;
}

Also, how specifically (i.e. with what specific syntax) does one set a global default for fetchtype in all methods, so that only some properties have to be overridden?

lexicore
  • 42,748
  • 17
  • 132
  • 221
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • Please see my answer below. May I ask you to leave your comments intact as they provide important context? Thank you. – lexicore Oct 28 '14 at 21:03

1 Answers1

2

Please see the similar question with the example on cascade asked previously:

customizing hibernate properties in hyperjaxb

And check the Hyperjaxb customizations schema which uses the JPA ORM schema:

This would result with something like:

<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
    <hj:persistence>
        <hj:default-many-to-one fetch="LAZY">
            <!-- ... -->
        </hj:default-many-to-one>
    </hj:persistence>
</jaxb:bindings>

If you want fetch="LAZY" on all of your associations, you'll have to customize default-one-to-one, default-one-to-many, default-many-to-many as well. These customizations will be applied globally (the semantics of the "default mappings"). You don't have to customize hundreds of properties.

Hyperjaxb actually has three levels of mappings:

  • Built-in defaults - built-in default mappings. These are Hyperjaxb inner defaults
  • Customized default mappings - defaults which you can customize per schema. So if you're not happy with defaults for some reason, you can provide your own default mappings - only there, where you want them different from the built-in defaults.
  • Customized property and association mappings or classes - things you customize per specific class, property or association. Again, only there where you want them different from the customized or built-in defaults.

These levels of customizations inherit from each other. So if you don't customize, you'll get the built-in defaults applied.


Concerning your feedback on the quality of the Hyperjaxb documentation. I absolutely agree that it is extremely far from being optimal (never disputed this, actually).

But this is the best state which is possible at the moment. I simply do not have the resources to actively develop or promote the project. Hyperjaxb is a niche tool which suites a very limited number of projects or applications. There is some, but very low user/developer interest which makes it economically not viable to develop and maintain it full or even part-time.

To put it frankly, my options at the moment are:

  • close and abandon the project
  • leave it on the low-flame maintenance

I'd close and abandon the project long ago, but:

  • I know there are users which are quire happy with Hyperjaxb, as it is.
  • I do not know any analog to Hyperjaxb, which would provide - even remotely - the same functionality and power. By "analog" I mean anything which would generate JPA-enabled classes based on the XML Schema. Of course there are other tools, like the brilliant MOXy which use other sources (Java classes, UML, whatever), but I know no other tool which would do XSD->Java+JPA. Unfortunately it seems like I have developed a unique tool.

So in this situation I can only leave the project on a very low flame, just fixing severe bugs and issues. With the documentation as good as it is it definitely raises the treshold on the required experience and eagerness to learn the tool. I would argue that there are all means for this: there are some 50+ pages of documentation, ready-to-run tutorials and samples, "just add water" template projects, some 60+ test projects available. But it sure does raise the treshold.

And I am truly sorry it does not work for you. Please accept my apologies for not fulfilling your expectations.

The feedback "your documentation is poor", no matter how true it is, is not a helpful contribution. Thank you for this feedback, but no, I don't have resources to work harder to make Hyperjaxb easier to use.

A helpful contribution would be:

Community
  • 1
  • 1
lexicore
  • 42,748
  • 17
  • 132
  • 221