Maven with hibernate tools

1.1k Views Asked by At

I am trying to generate my classes and the hibernate.cfg.xml with maven. Well i have classes in my project which depend on the generated java files so i will probably have to execute this process on project cleaning or so? I don't know how to configure this to work, so this is one question. Well i have a database.properties file which is ok and a lot of hbm.xml files which i have modified. Now i want to generate the hibernate.cfg.xml and all java files from the hbm.xml files and the database.properties file. My current maven entry looks like this:

<plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>hbm2java</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                    <configuration>
                        <components>
                            <component>
                                <name>hbm2java</name>
                                <implementation>configuration</implementation>
                                <outputDirectory>src/main/java</outputDirectory>
                            </component>
                        </components>
                        <componentProperties>
                            <jdk5>true</jdk5>
                            <ejb3>true</ejb3>
                            <propertyfile>src/main/resources/database.properties</propertyfile>
                        </componentProperties>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.0.8</version>
                </dependency>
                <dependency>
                    <groupId>cglib</groupId>
                    <artifactId>cglib-nodep</artifactId>
                    <version>2.1_3</version>
                </dependency>
            </dependencies>  
        </plugin>

Could anyone help me with this? I really don't know what to do, to get this thing working.

1

There are 1 best solutions below

0
Christian Beikov On

Well my solution is using my selfwritten plugin. Here you can find it: http://uploaded.to/file/j3j7b652

Sample usage:

   <plugin>
        <groupId>com.blazebit</groupId>
        <artifactId>HibernateCfgBuilder</artifactId>
        <version>1.0</version>
        <executions>
            <execution>
                <id>HibernateCfgBuilder</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>HibernateCfgBuilder</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <hbmXmlFilesDir>src/main/resources/com/company/model/</hbmXmlFilesDir>
            <configFile>target/classes/hibernate.cfg.xml</configFile>
            <packageName>com.company.model</packageName>
        </configuration>
    </plugin>

If you have any questions, ask. The configuration properties are all documented.