Question

I have found this page for ddl-generation and my current code looks like:

        <plugin>
            <!-- run "mvn clean install -Dmaven.test.skip=true -X hibernate3:hbm2ddl" to generate a schema -->
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <persistenceunit>Default</persistenceunit>
                    <outputfilename>schema.ddl</outputfilename>
                    <drop>false</drop>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                </componentProperties>
            </configuration>
        </plugin>

It works fine with the command "mvn clean install -Dmaven.test.skip=true -X hibernate3:hbm2ddl" but the ddl won't be generated by "mvn clean install". How can I change this?

Thank you!

Was it helpful?

Solution

You need to bind the execution of the hbm2ddl goal to a maven lifecycle phase. You could bind to install phase, but in case of ddl generation I'd recommend generate-sources phase (this will allow you to package generated ddl in built artifact before install if required).

eg add like

<executions>
  <execution>
      <id>execute-hbm2ddl</id>
      <phase>generate-sources</phase>
      <goals>
          <goal>hbm2ddl</goal>
      </goals>
      ... <!-- configuration here -->
  </execution>
</executions>

to get

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <id>execute-hbm2ddl</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>hbm2ddl</goal>
            </goals>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <componentProperties>
                    <persistenceunit>Default</persistenceunit>
                    <outputfilename>schema.ddl</outputfilename>
                    <drop>false</drop>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                </componentProperties>
            </configuration>
          </execution>
        </executions>
    </plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top