Documentation | Reference | Usage

Hyperjaxb3 configuration guide

This document describes Hyperjaxb3 configuration options.

Hyperjaxb2 Maven2 plugin versus standard JAXB2 Maven2 plugin or Ant

In this guide, we will primarily discuss how to configure Hyperjaxb3 via the Hyperjaxb3 Maven2 plugin. Namely, we'll concentrate on the configuration section of the plugin definition.

If you use a standard JAXB2 Maven2 plugin or Ant, configuring Hyperjaxb3 plugin with these tools is not much different. You just have to use the command line argument notation instead of the configuration element - simply prefix the element name with Xhyperjaxb3-ejb. For instance, if you want to specify the roundtripTestClassName configuration element, simply use the -Xhyperjaxb3-ejb-roundtripTestClassName command line argument. So, under Ant you'll have:

<xjc destdir="${basedir}/target/generated-sources/xjc" extension="true">
	<arg line="
		-Xequals
		-XhashCode
		-XtoString
		-Xhyperjaxb3-ejb
		-Xhyperjaxb3-ejb-roundtripTestClassName=RoundtripTest"/>
		<binding dir="${basedir}/src/main/resources">
	 	<include name="**/*.xjb"/>
	</binding>
	<schema dir="${basedir}/src/main/resources">
	 	<include name="**/*.xsd"/>
	</schema>
</xjc>

And with maven-jaxb2-plugin:

<plugin>
	<groupId>org.jvnet.jaxb2.maven2</groupId>
	<artifactId>maven-jaxb2-plugin</artifactId>
	<version>0.5</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<extension>true</extension>
		<plugins>
			<plugin>
				<groupId>org.jvnet.hyperjaxb3</groupId>
				<artifactId>hyperjaxb3-ejb-plugin</artifactId>
				<version>0.3</version>
			</plugin>
		</plugins>
		<args>
			<arg>-Xequals</arg>
			<arg>-XhashCode</arg>
			<arg>-Xhyperjaxb3-ejb</arg>
			<arg>-Xhyperjaxb3-ejb-roundtripTestClassName=RoundtripTest</arg>
		</args>
	</configuration>
</plugin>

With maven-hyperjaxb3-plugin this configuration is somewhat easier:

<plugin>
	<groupId>org.jvnet.hyperjaxb3</groupId>
	<artifactId>maven-hyperjaxb3-plugin</artifactId>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<extension>true</extension>
		<roundtripTestClassName>RoundtripTest</roundtripTestClassName>
	</configuration>
</plugin>

Hyperjaxb3 configurations options

roundtripTestClassName

Defines the fully qualified name of the roundtrip test class.
If you specify this, Hyperjaxb3 will generate the roundtrip test class which will perform the roundtrip testing of the generated mapping against the sample data.
If you omit this parameter, no roundtrip test will be generated.

persistenceUnitName

Provides the name of the persistent unit which will be generated for the processed schemas.

According to the JPA specification, Hyperjaxb3 generates the META-INF/persistence.xml file which lists the persistent classes. Below is an example of such a file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence version="1.0"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="org.jvnet.hyperjaxb3.ejb.tests.po">
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.Items$Item</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.Items</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.USAddress</class>
        <class>org.jvnet.hyperjaxb3.ejb.tests.po.PurchaseOrderType</class>
    </persistence-unit>
</persistence>

Persistent classes compose a persistence unit. By default, this unit is named after the schema package produced by JAXB2. However, you can override this name with the persistenceUnitName option.

generateTransientId

In some cases Hyperjaxb3 has to generate the primary key (id) fields in entities. Setting this flag to true forces Hyperjaxb3 to generate @XmlTransient id field. Default value is false.

catalog

In case your schema imports schema files from other locations and projects you can use a catalog resolver to map the import schemaLocation to a local file URL.

You may use the catalog configuration element to specify the location of your catalog file as follows:

<plugins>
     <plugin>
       <groupId>org.jvnet.hyperjaxb3</groupId>
       <artifactId>maven-hyperjaxb3-plugin</artifactId>
       ....
       <configuration>
          ...
         <catalog>${basedir}/catalog.xml</catalog>
       </configuration>
     </plugin>
   </plugins>

The catalog.xml file looks something like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
    <system systemId="http://acme.com/foo.xsd" uri="/home/najmi/my-project/src/main/resources/foo.xsd"/>
</catalog>