-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: problems using hibernatedoclet
PostPosted: Wed Dec 17, 2003 7:10 pm 
Newbie

Joined: Tue Dec 09, 2003 8:31 am
Posts: 17
I have been trying to get my application working in JBoss using this http://www.hibernate.org/66.html.

For some reason the hbm.xml files are not getting generated and therefore not getting listed in the jboss-service.xml

Here is my ant targets:
Code:
   <!-- =================================================================== -->
   <!-- Run Middlegen                                                       -->
   <!-- =================================================================== -->
   <target
      name="middlegen"
      description="Run Middlegen"
      unless="middlegen.skip"
      depends="check-driver-present,panic-if-driver-not-present" >
      <mkdir dir="${build.generate.dir}"/>

      <taskdef
         name="middlegen"
         classname="middlegen.MiddlegenTask"
         classpathref="middlegen.classpath"
      />

      <middlegen
         appname="middlegen"
         prefsdir="${middlegen.props}"
         gui="false"
         databaseurl="${database.url}"
         initialContextFactory="${java.naming.factory.initial}"
         providerURL="${java.naming.provider.url}"
         datasourceJNDIName="${name}.database"
         driver="${database.driver}"
         username="${database.userid}"
         password="${database.password}"
         schema="${database.schema}"
      >

               <table name="CT_CLIENT_PARM"/>
               <table name="DT_DAYPART"/>
               <table name="DT_OUTLET_DAYPART"/>
               <table name="DT_DAYPART_GROUP"/>
               <!-- table name="DT_DAYPART_GROUP_MEMBER"/ -->
               <table name="DT_TRAFFIC_UNIT"/>
               <table name="DT_UNIT_POST_IMP"/>
         
      <!-- Hibernate Plugin -->
      <hibernate destination="${build.generate.dir}"
         package="com.invisioninc.hibernate.data"
         genXDocletTags="true"/>

      </middlegen>
   </target>

   <target name="check-driver-present">
      <available file="${database.driver.file}" type="file" property="driver.present"/>
   </target>

   <target name="panic-if-driver-not-present" unless="driver.present">
      <fail>
      The JDBC driver you have specified ( ${database.driver.file} ) does not exist.
      </fail>
   </target>
   
   <!-- =================================================================== -->
   <!-- Generates the java files from the hbm.xml created by the middlegen  -->
   <!-- target.  It does not depend on the middlegen target however since   -->
   <!-- the database changes infrequently.  After a clean you will need to  -->
   <!-- run a middlegen and then a deploy to do a complete build            -->
   <!-- =================================================================== -->
   <target name="hbm2java"
      description="Generate .java from .hbm files." depends="init">
      <mkdir dir="${build.generate.dir}"/>
      <taskdef
         name="hbm2java"
         classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
         classpathref="hibernate.classpath"
      />
      
      <hbm2java output="${build.generate.dir}" classpathref="hibernate.classpath">
         <fileset dir="${build.generate.dir}">
            <include name="**/*.hbm.xml"/>
         </fileset>
      </hbm2java>
   </target>
   
   <!-- =================================================================== -->
   <!-- generates the hibernate HBM.XML files and SAR descriptor             -->
   <!-- =================================================================== -->
   <target name="generate-hibernate"
               description="Generates Hibernate class descriptor files and jboss-service.xml"
               depends="compile">
   
       <!-- copy additional resources for the Hibernate XDoclet task to the mergedir    -->
   
        <echo message="build.generate.dir = ${build.generate.dir}"/>
        <mkdir dir="${build.dir}/sar/hibernate"/>
       <copy todir="${build.dir}/sar/hibernate">
           <!-- fileset dir="${src.dir}">
               <include name="**/hibernate/hibernate-properties-*.xml"/>
           </fileset -->
           <fileset dir="${basedir}/config/sar/hibernate">
               <include name="jboss-service-custom.xdt"/>
           </fileset>
       </copy>
      
      <taskdef name="hibernatedoclet"
          classname="xdoclet.modules.hibernate.HibernateDocletTask">
          <classpath>
               <path refid="xdoclet.path"/>
               <fileset dir="${xdoclet.home}/lib" includes="*.jar"/>
          </classpath>
      </taskdef>
   
       <!-- Execute the hibernatedoclet task -->
       <hibernatedoclet
           destdir="${build.dir}/sar/hibernate"
           excludedtags="@version,@author,@todo,@see,@desc"
           addedtags="@xdoclet-generated at @copyright yourCompany,@author yourCompany,@version ${version}"
           force="${xdoclet.force}"
           mergedir="${build.dir}/sar/hibernate"
           verbose="true">
          
           <fileset dir="${build.generate.dir}">
               <include name="**/hibernate/data/*.java"/>
           </fileset>
          
           <!-- The hibernate subtask is used to generate the hbm files.  We did that with middlegen -->
           <hibernate version="2.0"/>
       
            <jbossservice
               destdir="${build.dir}/sar/hibernate"
               serviceName="Hibernate"
               jndiName="${hibernate.jndi.name}"
               dataSource="${hibernate.datasource.name}"
               dialect="${hibernate.dialect}"
               useOuterJoin="true"
            transactionManagerStrategy="net.sf.hibernate.transaction.JBossTransactionManagerLookup"
               transactionStrategy="net.sf.hibernate.transaction.JTATransactionFactory"
               userTransactionName="UserTransaction"
           />
   
       </hibernatedoclet>
   </target>


Here is one of the java files in the **/hibernate/data/ directory:
Code:
package com.invisioninc.hibernate.data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class DtDaypart implements Serializable {

    /** identifier field */
    private Integer daypartId;

    /** persistent field */
    private String name;

    /** persistent field */
    private BigDecimal listOrder;

    /** persistent field */
    private String activeInd;

    /** persistent field */
    private String defaultInd;

    /** persistent field */
    private Date auditDate;

    /** persistent field */
    private int auditUser;

    /** nullable persistent field */
    private String daysAndTimes;

    /** persistent field */
    private Set dtOutletDayparts;

    /** full constructor */
    public DtDaypart(Integer daypartId, String name, BigDecimal listOrder, String activeInd, String defaultInd, Date auditDate, int auditUser, String daysAndTimes, Set dtOutletDayparts) {
        this.daypartId = daypartId;
        this.name = name;
        this.listOrder = listOrder;
        this.activeInd = activeInd;
        this.defaultInd = defaultInd;
        this.auditDate = auditDate;
        this.auditUser = auditUser;
        this.daysAndTimes = daysAndTimes;
        this.dtOutletDayparts = dtOutletDayparts;
    }

    /** default constructor */
    public DtDaypart() {
    }

    /** minimal constructor */
    public DtDaypart(Integer daypartId, String name, BigDecimal listOrder, String activeInd, String defaultInd, Date auditDate, int auditUser, Set dtOutletDayparts) {
        this.daypartId = daypartId;
        this.name = name;
        this.listOrder = listOrder;
        this.activeInd = activeInd;
        this.defaultInd = defaultInd;
        this.auditDate = auditDate;
        this.auditUser = auditUser;
        this.dtOutletDayparts = dtOutletDayparts;
    }

    /**
     *            @hibernate.id
     *             generator-class="assigned"
     *             type="int"
     *             column="DAYPART_ID"
     *         
     */
    public Integer getDaypartId() {
        return this.daypartId;
    }

    public void setDaypartId(Integer daypartId) {
        this.daypartId = daypartId;
    }

    /**
     *            @hibernate.property
     *             column="NAME"
     *             length="50"
     *             not-null="true"
     *         
     */
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     *            @hibernate.property
     *             column="LIST_ORDER"
     *             length="4"
     *             not-null="true"
     *         
     */
    public BigDecimal getListOrder() {
        return this.listOrder;
    }

    public void setListOrder(BigDecimal listOrder) {
        this.listOrder = listOrder;
    }

    /**
     *            @hibernate.property
     *             column="ACTIVE_IND"
     *             length="1"
     *             not-null="true"
     *         
     */
    public String getActiveInd() {
        return this.activeInd;
    }

    public void setActiveInd(String activeInd) {
        this.activeInd = activeInd;
    }

    /**
     *            @hibernate.property
     *             column="DEFAULT_IND"
     *             length="1"
     *             not-null="true"
     *         
     */
    public String getDefaultInd() {
        return this.defaultInd;
    }

    public void setDefaultInd(String defaultInd) {
        this.defaultInd = defaultInd;
    }

    /**
     *            @hibernate.property
     *             column="AUDIT_DATE"
     *             length="7"
     *             not-null="true"
     *         
     */
    public Date getAuditDate() {
        return this.auditDate;
    }

    public void setAuditDate(Date auditDate) {
        this.auditDate = auditDate;
    }

    /**
     *            @hibernate.property
     *             column="AUDIT_USER"
     *             length="6"
     *             not-null="true"
     *         
     */
    public int getAuditUser() {
        return this.auditUser;
    }

    public void setAuditUser(int auditUser) {
        this.auditUser = auditUser;
    }

    /**
     *            @hibernate.property
     *             column="DAYS_AND_TIMES"
     *             length="100"
     *         
     */
    public String getDaysAndTimes() {
        return this.daysAndTimes;
    }

    public void setDaysAndTimes(String daysAndTimes) {
        this.daysAndTimes = daysAndTimes;
    }

    /**
     *            @hibernate.set
     *             lazy="true"
     *             inverse="true"
     *           @hibernate.collection-key
     *            column="DAYPART_ID"
     *            @hibernate.collection-one-to-many
     *             class="com.invisioninc.hibernate.data.DtOutletDaypart"
     *         
     */
    public Set getDtOutletDayparts() {
        return this.dtOutletDayparts;
    }

    public void setDtOutletDayparts(Set dtOutletDayparts) {
        this.dtOutletDayparts = dtOutletDayparts;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("daypartId", getDaypartId())
            .toString();
    }

    public boolean equals(Object other) {
        if ( !(other instanceof DtDaypart) ) return false;
        DtDaypart castOther = (DtDaypart) other;
        return new EqualsBuilder()
            .append(this.getDaypartId(), castOther.getDaypartId())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getDaypartId())
            .toHashCode();
    }

}


I don't understand why this is not working. It seems pretty straight forward.

I am using Hibernate 2.1 final with XDoclet 1.2, not sure if it is beta-3 or beta4. All the libs in xdoclet have a suffix of 1.2b4 but the index.html in the docs dir says beta3.

The ant tasks above use middlegen to create the hbm.xml files, then hbm2java to create java files with the hibernate xdoclet tags as you can see in the java file above. The hibernatedoclet task should then see all the xdoclet tags in the java and create the hbm.xml files ( I know this is redundant since middlegen already did it - that is a whole nother issue).

Lastly here is the jboss-service.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>

<!-- Generated file - Do not edit! -->

<server>
   <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
       <depends>jboss.jca:service=RARDeployer</depends>
       <attribute name="MapResources"></attribute>
       <attribute name="JndiName">java:/HibernateFactory</attribute>
       <attribute name="Datasource">java:/OracleDS</attribute>
       <attribute name="Dialect">net.sf.hibernate.dialect.Oracle9Dialect</attribute>
       <attribute name="UseOuterJoin">true</attribute>
       <attribute name="ShowSql">false</attribute>
       <attribute name="UserTransactionName">UserTransaction</attribute>
       <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
       <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
         <depends>jboss.jca:service=LocalTxCM,name=OracleDS</depends>
    <attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
   </mbean>

</server>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Need to confirm by seeing the Middlegen generated HBM file. Anyway, your Java POJO looks fine other than the missing XDoclet markup for the class name. This should be present in the Middlegen generated HBM as a meta tag. (Note: there is a typo in the current release here but that is not the problem here [yet]). If the Meta Tag is there then possibly hbm2java has not passed the tag onto the class generation or the typo has stopped it from generating the Meta tag information as its the wrong category (Which I suppose is likely). It generates the Meta tag as field-description but it should be class-description. Change this in the HBM file (or edit the Middlegen hibernate.vm file appropriately) and try XDoclet again. BTW: This has been fixed but we are doing pre-work for Middlegen 2 final (Maybe out by Christmas).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 8:43 am 
Newbie

Joined: Tue Dec 09, 2003 8:31 am
Posts: 17
David,

I got three words for ya, "You Da Man".

I changed the hibernate.vm file to class-description, where it had field-description. Reran my ant targets and I now have hbm files and the jboss-service.xml lists out the files.

Thanks for your prompt response.

Craig


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 5:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
No problem - Glad it fixed your problem. You could add a generator to hbm2java to get it the generate the JBoss service file. There is a new velocity extension that I suppose could be used (I need to look into this work myself).


Top
 Profile  
 
 Post subject: Re: problems using hibernatedoclet
PostPosted: Thu Dec 16, 2010 5:56 am 
Newbie

Joined: Thu Dec 16, 2010 3:07 am
Posts: 5
Hey, same here! I have always wondered as to why this situation still persists. You know what! The JBoss versions we are using are quite different and yet still this issue is found on both of our versions and that shows they have not tried anything until now in order to fix the issue. I still, however do not understand why or what is causing the problem or what is preventing the hbm. Xml files from generating!

_________________
Stereolithography


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.