LINUX.ORG.RU

История изменений

Исправление totik, (текущая версия) :

В pom.xml в build/plugins добавь:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution> <!--start with mvn antrun:run@hbm2java -->
                        <id>hbm2java</id>
                        <phase>none</phase>
                        <configuration>
                            <target>
                                <property name="compile_classpath" refid="maven.compile.classpath"/>
                                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                                <property name="test_classpath" refid="maven.test.classpath"/>
                                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                                <echo message="Start generating entities..."/>
                                <taskdef name="hibernatetool"
                                         classname="org.hibernate.tool.ant.HibernateToolTask"/>
                                <hibernatetool
                                        destdir="src/main/java/">
                                    <classpath>
                                        <path location="${project.build.directory}/classes" />
                                    </classpath>
                                    <jdbcconfiguration
                                            revengfile="src/main/resources/hibernate.reveng.xml"
                                            packagename="com.mydomain"
                                            detectmanytomany="true"
                                            configurationfile="src/main/resources/hibernate.cfg.xml"
                                            reversestrategy="com.mydomain.MyReverseEngineeringStrategy"
                                    />
                                    <hbm2java jdk5="true" ejb3="true"/>
                                </hibernatetool>
                                <echo message="End generating entities."/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-core</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-entitymanager</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate.common</groupId>
                        <artifactId>hibernate-commons-annotations</artifactId>
                        <version>${hibernate-annotations.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate.javax.persistence</groupId>
                        <artifactId>hibernate-jpa-2.1-api</artifactId>
                        <version>1.0.0.Final</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-tools</artifactId>
                        <version>${hibernate.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>*</groupId>
                                <artifactId>*</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>javax.transaction</groupId>
                        <artifactId>jta</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>freemarker</groupId>
                        <artifactId>freemarker</artifactId>
                        <version>2.3.8</version>
                    </dependency>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgresql.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>commons-collections</groupId>
                        <artifactId>commons-collections</artifactId>
                        <version>3.2.1</version>
                    </dependency>
                </dependencies>
            </plugin>
Командой mvn antrun:run@hbm2java ты получишь сгенерированные сущности, но увы, в аннотациях hibernate. Если найдешь способ генерирования сущностей в аннотациях JPA, дай знать. В моем случае все было сгенерировано как надо, связи таблиц определились точно.

Исходная версия totik, :

В pom.xml в build/plugins добавь:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution> <!--start with mvn antrun:run@hbm2java -->
                        <id>hbm2java</id>
                        <phase>none</phase>
                        <configuration>
                            <target>
                                <property name="compile_classpath" refid="maven.compile.classpath"/>
                                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                                <property name="test_classpath" refid="maven.test.classpath"/>
                                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                                <echo message="Start generating entities..."/>
                                <taskdef name="hibernatetool"
                                         classname="org.hibernate.tool.ant.HibernateToolTask"/>
                                <hibernatetool
                                        destdir="src/main/java/">
                                    <classpath>
                                        <path location="${project.build.directory}/classes" />
                                    </classpath>
                                    <jdbcconfiguration
                                            revengfile="src/main/resources/hibernate.reveng.xml"
                                            packagename="com.mydomain"
                                            detectmanytomany="true"
                                            configurationfile="src/main/resources/hibernate.cfg.xml"
                                            reversestrategy="com.mydomain.MyReverseEngineeringStrategy"
                                    />
                                    <hbm2java jdk5="true" ejb3="true"/>
                                </hibernatetool>
                                <echo message="End generating entities."/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-core</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-entitymanager</artifactId>
                        <version>${hibernate.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate.common</groupId>
                        <artifactId>hibernate-commons-annotations</artifactId>
                        <version>${hibernate-annotations.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate.javax.persistence</groupId>
                        <artifactId>hibernate-jpa-2.1-api</artifactId>
                        <version>1.0.0.Final</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-tools</artifactId>
                        <version>${hibernate.version}</version>
                        <exclusions>
                            <exclusion>
                                <groupId>*</groupId>
                                <artifactId>*</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>javax.transaction</groupId>
                        <artifactId>jta</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>freemarker</groupId>
                        <artifactId>freemarker</artifactId>
                        <version>2.3.8</version>
                    </dependency>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgresql.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                        <version>1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>commons-collections</groupId>
                        <artifactId>commons-collections</artifactId>
                        <version>3.2.1</version>
                    </dependency>
                </dependencies>
            </plugin>
Командой mvn antrun:run@hbm2java ты получишь сгенерированные сущности, но увы, в аннотациях hibernate. Если найдешь способ генерирования сущностей в аннотациях JPA, дай знать.