JAXB Java EE generates an entity class from a schema

I am using the Maven plugin for JAXB to create classes from an XML schema document. My POM contains the following

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <version>1.5</version> <executions> <execution> <goals> <goal>xjc</goal> </goals> <phase>generate-sources</phase> </execution> </executions> <configuration> <clearOutputDir>false</clearOutputDir> <outputDirectory>src/main/java</outputDirectory> <schemaDirectory>src/main/webapp/schemas</schemaDirectory> <includeSchema>**/*.xsd</includeSchema> <bindingDirectory>src/main/resources/bindings</bindingDirectory> <enableIntrospection>false</enableIntrospection> </configuration> </plugin> 

I use the Eclipselink specification for JPA 2. When JAXB generates a class according to the schema, it does not include the following annotations.

 @Entity @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 

Right now, I just add them manually every time I do a clean compilation with Maven. I am wondering, is there anyway for the JAXB plugin to annotate the class file with these annotations included when it generates classes?

+4
source share
1 answer

The XJC compiler used by JAXB has an api plugin that allows you to customize the generated Java code. It seems that the plugin adds arbitrary annotations , maybe this already solves your problem.

For a more complex example of features, you can look at the source code for a smooth api plugin .

+1
source

All Articles