Integrating Hyperjaxb3 in builds

Integrating Hyperjaxb3 in builds

Overview

Using Hyperjaxb3 plugin for XJC

Using Hyperjaxb3 in Ant builds

Using Hyperjaxb3 plugin in Maven builds

Using Hyperjaxb3 with maven-jaxb2-plugin

Using maven-hyperjaxb3-plugin

Generating the database schema

When building the project, you may also want to generate a database schema (DDL) for the persistence unit which was created by the Hyperjaxb3. This is done differently depending in your build tool and the persistence provider you use. The following sections illustrate some of the setups.

Using hbm2ddl from Hibernate Tools

Hibernate includes the Hibernate Tools sub-project which provides the hbm2ddl database schema exporter.

Maven usage

The easiest way of integrating hbm2ddl in your Maven builds is the Hibernate3 Maven Plugin. Here's a sample configuration:

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>hibernate3-maven-plugin</artifactId>
	<executions>
		<execution>
			<phase>process-classes</phase>
			<goals>
				<goal>hbm2ddl</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<components>
			<component>
				<name>hbm2ddl</name>
				<implementation>jpaconfiguration</implementation>
				<outputDirectory>target/generated-resources/hbm2ddl</outputDirectory>
			</component>
		</components>
		<componentProperties>
			<!-- Name of the persistence unit -->
			<persistenceunit>com.acme.foo</persistenceunit>
			<!-- Hibernate properties -->
			<propertyfile>src/test/resources/persistence.properties</propertyfile>
			<outputfilename>schema.ddl</outputfilename>
			<drop>false</drop>
			<create>true</create>
			<export>false</export>
			<format>true</format>
		</componentProperties>
	</configuration>
</plugin>

It is important that this plugin is invoked, after the compile phase (for instance, in the process-classes phase) since it needs the compiled classes for schema generation.

Hibernate properties file must at least provide the dialect:

persistence.properties
hibernate.dialect=org.hibernate.dialect.HSQLDialect

Using Hyperjaxb3 with Apache CXF

Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.

One of the features of Apache CXF is WSDL-to-Java code generation with the cxf-codegen-plugin for Maven. You can invoke Hyperjaxb3 from this plugin to turn some of the WSDL- or schema-derived classes JPA-conform.

Invoking Hyperjaxb3 from cxf-codegen-plugin

Since 0.5.5.

The cxf-codegen-plugin uses JAXB schema compiler (XJC) internally. This gives the possibility to invoke Hyperjaxb3 as a normal XJC plugin. To achieve this, you need to do the following:

Here's an example of the cxf-codegeb-plugin configuration:

A fragment of pom.xml
<plugin>
	<groupId>org.apache.cxf</groupId>
	<artifactId>cxf-codegen-plugin</artifactId>
	<executions>
		<execution>
			<id>generate-sources</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>wsdl2java</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<wsdlOptions>
			<wsdlOption>
				<wsdl>${basedir}/src/main/wsdl/myService.wsdl</wsdl>
				<bindingFiles>
					<!-- JAX-WS bindings -->
					<bindingFile>${basedir}/src/main/wsdl/binding.xml</bindingFile>
					<!-- XJC bindings -->
					<bindingFile>${basedir}/src/main/wsdl/binding.xjb</bindingFile>
				</bindingFiles>
				<extraargs>
					<!-- Turns on the hashCode plugin -->
					<extraarg>-xjc-XhashCode</extraarg>
					<!-- Turns on the equals plugin -->
					<extraarg>-xjc-Xequals</extraarg>
					<!-- Turns on the Hyperjaxb3 EJB plugin -->
					<extraarg>-xjc-Xhyperjaxb3-ejb</extraarg>
				</extraargs>
			</wsdlOption>
		</wsdlOptions>
	</configuration>
	<dependencies>
		<dependency>
			<groupId>org.jvnet.jaxb2_commons</groupId>
			<artifactId>jaxb2-basics</artifactId>
			<version><!-- version --></version>
		</dependency>
		<dependency>
			<groupId>org.jvnet.hyperjaxb3</groupId>
			<artifactId>hyperjaxb3-ejb-plugin</artifactId>
			<version><!-- version --></version>
		</dependency>
	</dependencies>
</plugin>

See this tutorial for an example.


Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Activity
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide
- Impressum

Your Account

Log In

 

Other Features

Add Content