0

I am having a JPA entity for "User". I want to generate a sql statement for this entity using maven hibernate3 Plugin. I tried using persistence.xml as configured in https://stackoverflow.com/questions/6855119/how-to-generate-schema-through-hibernate3hbdml-in-persistence-xml but my configuration fails. How to configure persistence.xml with any simple database and access the table created using maven hibernate3:hbm2ddl plugin.

1 Answer 1

5

Here is my example configuration for HSQLdb which generates src/main/resources/db-scheme.sql:

From pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <components>
            <component>
                <name>hbm2ddl</name>
                <implementation>jpaconfiguration</implementation>
                <outputDirectory>
                    src/main/resources
                </outputDirectory>
            </component>
        </components>
        <componentProperties>
            <console>false</console>
            <format>true</format>
            <jdk5>true</jdk5>
            <propertyfile>
                src/main/resources/database.properties
            </propertyfile>
            <outputfilename>db-scheme.sql</outputfilename>
            <export>false</export>
        </componentProperties>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.5.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.6.5.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
    </dependencies>
</plugin>

src/main/resources/database.properties:

hibernate.formatSql=true
hibernate.hbm2ddl.auto=validate

# needed for hibernate3-maven-plugin
hibernate.dialect=org.hibernate.dialect.HSQLDialect

src/main/resources/META-INF/persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="DefaultPersistenceUnit" transaction-type="RESOURCE_LOCAL" />
</persistence>

HTH

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.