0

antタスクを使用してマッピング(hbm.xml)をpojoクラスにエクスポートしています。マップされたディレクトリにPOJOファイルを生成します。しかし、クラスはパッケージステートメントを見逃しています。デフォルトのパッケージですべてのファイルを作成するだけです

// default package
// Generated Aug 23, 2012 12:34:40 PM by Hibernate Tools 3.2.2.GA

これがタスクのantビルドファイルです。

    <project name="Hibernate Tools for Ant - hbm2java" default="gensrc">

    <path id="tools">
        <path location="lib/hibernate-tools-3.2.3.GA.jar"/>
        <path location="lib/hibernate3.6.10.jar"/>
        <path location="lib/freemarker-2.3.8.jar"/>
        <path location="lib/hsqldb-2.2.4.jar"/>
        <path location="lib/commons-logging.jar"/>
        <path location="lib/dom4j-1.6.1.jar"/>
        <path location="lib/slf4j-api-1.6.1.jar"/>
        <path location="lib/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
    </path>
    <taskdef name="gen-src" classname="org.hibernate.tool.ant.HibernateToolTask"
             classpathref="tools"/>
    <target name="gensrc">
        <gen-src destdir="src/main/java">
            <configuration
                    configurationfile="src/main/resources/hibernate.cfg.xml">
                <fileset dir="src/main/java/com/kee/example/domain/maps">
                    <include name="Event.hbm.xml"/>
                </fileset>
            </configuration>
            <hbm2java destdir="src/main/java/com/kee/example/domain"/>
        </gen-src>
    </target>
</project>

デフォルトのPojo.ftl(hibernate-tools.jar内)には、次のような宣言があります

 ${pojo.getPackageDeclaration()}
// Generated ${date} by Hibernate Tools ${version}

生成されたPOJOで正しいパッケージ宣言を行うには、何を変更する必要がありますか。

更新: これが私のマッピングファイルです

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.kee.example.domain">
    <meta attribute="generated-class">EventBase</meta>
    <meta attribute="implement-equals">true</meta>
    <meta attribute="scope-field">protected</meta>
    <class name="com.kee.example.domain.Event" table="event">
        <id name="id" type="java.lang.Long">
            <generator class="native"/>
        </id>
        <property name="eventDate" type="timestamp"/>
        <property name="eventString" type="java.lang.String"/>
    </class>
</hibernate-mapping>
4

1 に答える 1

0

Mavenでも同じ問題が発生し、理由はわかりませんが、 jdbcconfigurationの代わりにannotationconfigurationを使い始めると解決しました。

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>annotationconfiguration</implementation>
                        <outputDirectory>${db.src.dir}</outputDirectory>
                    </component>
                    <component>
                        <name>hbm2java</name>
                        <implementation>annotationconfiguration</implementation>
                        <outputDirectory>src/main/java</outputDirectory>
                    </component>
                </components>
                <componentProperties>
                    <drop>true</drop>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                    <jdk5>true</jdk5>
                    <ejb3>true</ejb3>
                    <outputfilename>${ddl.file}</outputfilename>
                    <templatepath>src/main/resources/hibernate-template</templatepath>
                    <delimiter>;</delimiter>
                    <configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
                </componentProperties>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>${jdbc.groupId}</groupId>
                    <artifactId>${jdbc.artifactId}</artifactId>
                    <version>${jdbc.version}</version>
                </dependency>
            </dependencies>
        </plugin>

注釈付きのpojoクラスが必要なかったので、*。ftlファイルのコードにコメントを付けました。

于 2013-02-16T21:14:46.357 に答える