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>