Generate hibernate entity beans from XSD

2019-03-16 00:01发布

问题:

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?

回答1:

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



回答2:

You could use HyperJAXB to generate a JAXB model with JPA annotations. Hibernate implements the JPA specification:

  • http://java.net/projects/hyperjaxb/