Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate hibernate entity beans from XSD

My requirement is to save a huge XML values to database.
After analyzing few options I finalized that generate entity bean classes from huge xml and then persist it using hibernate.
I am opting out of creating hbm files and going for hibernate annotations.In this way I will be generating Java classes from XSD using JAXB and them manually add hibernate annotations.
Is there any eclipse plugin or util framework which can generate entity classes from XSD with default hibernate annotations?

like image 768
Himanshu Yadav Avatar asked Jul 05 '12 12:07

Himanshu Yadav


1 Answers

Here's some documentation:

http://confluence.highsource.org/display/HJ3/Making+schema-derived+classes+ready+for+JPA

http://java.net/projects/hyperjaxb

Here's a working example for a project I have completed:

  <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.7.4</version>
    <dependencies>
                  <dependency>
                          <groupId>org.jvnet.hyperjaxb3</groupId>
                          <artifactId>hyperjaxb3-ejb-plugin</artifactId>
                          <version>0.5.5</version>
                  </dependency>
            </dependencies>
    <executions>
      <execution>
        <id>generate-domain1</id>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <strict>false</strict>
          <schemaIncludes>
            <value>account.xsd</value>
            <value>customer.xsd</value>
            <value>address.xsd</value>
          </schemaIncludes>
          <bindingIncludes>
            <include>domain-bindings.xjb</include>
          </bindingIncludes>
          <extension>true</extension>
          <generatePackage>your.package.here</generatePackage>
          <generateDirectory>${project.build.directory}/generated-sources/jaxbandjpa</generateDirectory>
          <args>
            <arg>-Xannotate</arg>
            <arg>-Xhyperjaxb3-ejb</arg>
           </args>                  
           <plugins>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics</artifactId>
              <version>0.6.0</version>
            </plugin>
            <plugin>
              <groupId>org.jvnet.jaxb2_commons</groupId>
              <artifactId>jaxb2-basics-annotate</artifactId>
              <version>0.6.0</version>
            </plugin>
          </plugins>
        </configuration>
      </execution>
    </executions>
  </plugin>

hope it helps

like image 63
user1459641 Avatar answered Sep 23 '22 10:09

user1459641