Search code examples
mavenreverse-engineeringhibernate-tools

Reverse engineering with custom ReverseEgineeringStrategy


I want to do reverse engineering (generate java classes from my database) with a custom ReverseEgineeringStrategy. I succeeded to do this using hibernate-tools plugin for eclipse. But I want to use hibernate3-maven-plugin to do this. I searched a lot for an example but neither of the examples I found worked for me.

If anyone know how we can do this, I appreciate his help.


Solution

  • I have tried hibernate3-maven-plugin version 3.0

    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>
    

    Unfortunately I had errors and I didn't succeeded to make it work (messages of exceptions didn't help me a lot neither).

    So I tried the version 2.2 and it works perfectly, here my pom.xml

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>hbm2java</id>
                        <phase>install</phase>
                        <goals>
                            <goal>hbm2java</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <components>
                                <component>
                                    <name>hbm2java</name>
                                    <implementation>jdbcconfiguration</implementation>
                                    <outputDirectory>target/generatedClasses</outputDirectory>
                                </component>
                            </components>
                            <componentProperties>
                                <jdk5>true</jdk5>
                                <ejb3>false</ejb3>
                                <revengfile>${basedir}\hibernate.reveng.xml</revengfile>
                                <reversestrategy>com.it.mybatis.MyReverseEngineeringStrategy</reversestrategy>
                                <propertyfile>${basedir}\database.properties</propertyfile>
                            </componentProperties>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc14</artifactId>
                        <version>10.2.0.2.0</version>
                    </dependency>
                    <dependency>
                        <groupId>cglib</groupId>
                        <artifactId>cglib-nodep</artifactId>
                        <version>2.1_3</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    
    
    <dependencies>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.5</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>4.0.0-CR1</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <version>10.2.0.2.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>