-
Notifications
You must be signed in to change notification settings - Fork 99
HyperJAXB3 Customizing default mappings
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 defaulthj: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.
<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.
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>
- Home
- Migration guide
-
JAXB Maven Plugin
- Quick Start
-
User Guide
- Basic Usage
- Specifying What To Compile
- Referencing Resources in Maven Artifacts
- Using Catalogs
- Using Episodes
- Modular Schema Compilation
- Controlling the Output
- Using JAXB Plugins
- Using a Specific JAXB Version
- Configuring Extension, Validation and XML Security
- IDE Integration
- Miscellaneous
- Configuring Proxies
- Maven Documentation
- Configuration Cheat Sheet
- Common Pitfalls and Problems
-
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
-
JAXB2 Basics Plugins List
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Commons Lang Plugin
- Default Value Plugin
- Fluent API Plugin
- Namespace Prefix Plugin
- Value Constructor Plugin
- Boolean Getter Plugin
- CamelCase Plugin
- XML ElementWrapper Plugin
- Parent Pointer Plugin
- Property Listener Injector Plugin
- Annox
- JAXB Annotate Plugin
-
HyperJAXB3
- Build System Support
- Customization Guide
- Databases
- Development guide
- Extension guide
- FAQ
- IDE Support
- Java Persistence
- JAXB
- JDK Support
- Project Templates
-
Reference
- Adding vendor-specific annotations
- Features
- Integrating Hyperjaxb3 in builds
- Introduction
- Making schema-derived classes ready for JPA
- Adding required properties
- Applying workarounds for JAXB vs. JPA conflicts
- Enforcing top-level classes
- Generating equals and hashCode methods
- Generating ORM metadata
- Generating persistence unit descriptor
- JPA 2 Support
- Making classes serializable
- Testing generated mappings
- Reference - single page
- Related Projects
- Sample projects
- Solutions
- Target Scenarios
- Test Projects
- Tutorials
- Best Practices
- FAQ
- Sample Projects
- Support
- License
- Distribution