Skip to content

HyperJAXB3 Customizing default mappings

Laurent Schoelens edited this page May 17, 2024 · 1 revision

Customizing default mappings

Customizing default mappings - Introduction

Although Hyperjaxb3 is highly customizable, you don't actually have to customize. If you don't customize, Hyperjaxb3 will follow its default strategies when generating mappings. For instance default strategy for collection mapping is one-to-many with join columns, default generated identifier property will be called Hjid and typed as long and so on.

No matter how reasonable and good default mappings are, there may be need to override the globally - for all entities, all properties. For instance, you may want map 1:M properties using a join table (instead of the default join column). While you you can surely use the hj:one-to-many customization for each of your 1:M properties, this will require a lot of work.

To address such "global customization tasks" Hyperjaxb3 provides the possibility to customize default mappings. This is accomplished by customizing the schema with the hj:persistence element:

<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
    <hj:persistence>
        <hj:default-one-to-many>
            <orm:join-table/>
        </hj:default-one-to-many>
    </hj:persistence>
</jaxb:bindings>

The hj:persistence element may contain a number of sub-elements which customize default mappings, applied globally. For example, you may make all generated identifier properties to be named Id (instead of Hjid):

<hj:persistence>
    <hj:default-generated-id name="Id"/>
</hj:persistence>

As the matter of fact, Hyperjaxb3 uses the hj:persistence element internally to define the default mappings:

So when you define your hj:persistence customization, you actually override the default hj:persistence.

You don't need to provide the complete configuration of the customization element. It is enough to define only what you need to override. Missing attrbutes and elements will be taken from default mappings.

Overriding and merging customizations

Customizing the default entity

Customizing the default mapped superclass

Customizing the default embeddable

Customizing the default identifier property

Customizing the default generated identifier property

See hj:default-generated-id.

<hj:persistence>
    <hj:default-generated-id name="MyId" transient="true">
        <orm:column name="MY_ID"/>
    </hj:default-generated-id>
</hj:persistence>

This will make all the generated identifier properties to be named MyId (instead of Hjid) by default. They'll be also generated transient.

Customizing the default embedded identifier property

Customizing the default version property

Customizing the default generated version property

See hj:default-generated-version.

Example:

<hj:persistence>
    <hj:default-generated-version name="Version"/>
</hj:persistence>

This will make all the generated version properties to be named Version (instead of Hjversion) by default.

Note that Hyperjaxb3 will not generate version properties by default. If you want to generate version property for a certain type, use the hj:generated-version customization. If you want to generate version properties for all the types, set the forced attribute of the hj:default-generated-version element to true:

<hj:persistence>
    <hj:default-generated-version forced="true"/>
</hj:persistence>

Customizing the default basic property

Customizing the default to-one mapping

Customizing the default to-many mapping

Customizing the default many-to-one mapping

Customizing the default one-to-many mapping

Customizing the default one-to-one mapping

Customizing the default many-to-many mapping

Customizing the default embedded mapping

Clone this wiki locally