Keerthi
Keerthi

Reputation: 80

hibernatetools ant task - hbm2java - creates pojo without package statement

I'm exporting my mapping (hbm.xml) to pojo classes using ant task. It generates the POJO files in the mapped directory. But the Classes miss the Package statement. It simply creates all files in default package

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

Here is my ant build file for the task.

    <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>

the default Pojo.ftl (inside hibernate-tools.jar) has the declaration as below

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

what should i be changing in order to have correct package declaration in the generated POJO.

Update: Here is my Mapping file

<?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>

Upvotes: 0

Views: 3538

Answers (1)

Amitabha Roy
Amitabha Roy

Reputation: 797

I was getting the same problem in maven and not sure about the reason but it was resolved once I started using annotationconfiguration instead of jdbcconfiguration.

<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>

I did not want the annotated pojo classes so I had commented codes in *.ftl files.

Upvotes: 0

Related Questions