I have been using middlegen and hibernate to create a bottum-up persistence. I noticed a new release of Middlegen was out as well as a new middlegen hibernate plugin, so I downloaded new copies. I replaced the following jar files:
middlegen-2.0-b2-dev.jar
middlegen-entitybean-plugin-2.0-b2-dev.jar
middlegen-hibernate-plugin-2.0-b2-dev.jar
with:
middlegen-2.0-vo.jar
middlegen-entitybean-plugin-2.0-vo.jar
middlegen-hibernate-plugin-2.0-vo.jar
and reran my build. But I get errors in the hibernatedoclet step. It looks like the hbm2java step in my build is behaving differently due to the recent changes in the hbm.xml files.
This is what the hbm.xml file looked like with the old jars:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.invisioninc.hibernate.data.DtOutletDaypart"
table="DT_OUTLET_DAYPART"
>
<meta attribute="class-description">
@hibernate.class
table="DT_OUTLET_DAYPART"
</meta>
<composite-id name="comp_id" class="com.invisioninc.hibernate.data.DtOutletDaypartPK">
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
</meta>
<!-- bi-directional many-to-one association to DtOutlet -->
<key-many-to-one
name="dtOutlet"
class="com.invisioninc.hibernate.data.DtOutlet"
>
<column name="OUTLET_CD" />
</key-many-to-one>
<!-- bi-directional many-to-one association to DtDaypart -->
<key-many-to-one
name="dtDaypart"
class="com.invisioninc.hibernate.data.DtDaypart"
>
<column name="DAYPART_ID" />
</key-many-to-one>
</composite-id>
<property
name="defaultInd"
type="java.lang.String"
column="DEFAULT_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="DEFAULT_IND"
length="1"
not-null="true"
</meta>
</property>
<property
name="auditDate"
type="java.sql.Timestamp"
column="AUDIT_DATE"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="AUDIT_DATE"
length="7"
not-null="true"
</meta>
</property>
<property
name="auditUser"
type="int"
column="AUDIT_USER"
not-null="true"
length="6"
>
<meta attribute="field-description">
@hibernate.property
column="AUDIT_USER"
length="6"
not-null="true"
</meta>
</property>
<property
name="daysAndTimes"
type="java.lang.String"
column="DAYS_AND_TIMES"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="DAYS_AND_TIMES"
length="100"
</meta>
</property>
<property
name="listOrder"
type="java.math.BigDecimal"
column="LIST_ORDER"
not-null="true"
length="4"
>
<meta attribute="field-description">
@hibernate.property
column="LIST_ORDER"
length="4"
not-null="true"
</meta>
</property>
<property
name="activeInd"
type="java.lang.String"
column="ACTIVE_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="ACTIVE_IND"
length="1"
not-null="true"
</meta>
</property>
<property
name="stewActiveInd"
type="java.lang.String"
column="STEW_ACTIVE_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="STEW_ACTIVE_IND"
length="1"
not-null="true"
</meta>
</property>
<!-- associations -->
</class>
</hibernate-mapping>
and here is the java code that is generated from that using the old jars.
Code:
package com.invisioninc.hibernate.data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @hibernate.class
* table="DT_OUTLET_DAYPART"
*
*/
public class DtOutletDaypart implements Serializable {
/** identifier field */
private com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id;
/** persistent field */
private String defaultInd;
/** persistent field */
private Date auditDate;
/** persistent field */
private int auditUser;
/** nullable persistent field */
private String daysAndTimes;
/** persistent field */
private BigDecimal listOrder;
/** persistent field */
private String activeInd;
/** persistent field */
private String stewActiveInd;
/** full constructor */
public DtOutletDaypart(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id, String defaultInd, Date auditDate, int auditUser, String daysAndTimes, BigDecimal listOrder, String activeInd, String stewActiveInd) {
this.comp_id = comp_id;
this.defaultInd = defaultInd;
this.auditDate = auditDate;
this.auditUser = auditUser;
this.daysAndTimes = daysAndTimes;
this.listOrder = listOrder;
this.activeInd = activeInd;
this.stewActiveInd = stewActiveInd;
}
/** default constructor */
public DtOutletDaypart() {
}
/** minimal constructor */
public DtOutletDaypart(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id, String defaultInd, Date auditDate, int auditUser, BigDecimal listOrder, String activeInd, String stewActiveInd) {
this.comp_id = comp_id;
this.defaultInd = defaultInd;
this.auditDate = auditDate;
this.auditUser = auditUser;
this.listOrder = listOrder;
this.activeInd = activeInd;
this.stewActiveInd = stewActiveInd;
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public com.invisioninc.hibernate.data.DtOutletDaypartPK getComp_id() {
return this.comp_id;
}
public void setComp_id(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id) {
this.comp_id = comp_id;
}
/**
* @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.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="STEW_ACTIVE_IND"
* length="1"
* not-null="true"
*
*/
public String getStewActiveInd() {
return this.stewActiveInd;
}
public void setStewActiveInd(String stewActiveInd) {
this.stewActiveInd = stewActiveInd;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof DtOutletDaypart) ) return false;
DtOutletDaypart castOther = (DtOutletDaypart) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
Here is the hbm.xml file with the new jars:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.invisioninc.hibernate.data.DtOutletDaypart"
table="DT_OUTLET_DAYPART"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="DT_OUTLET_DAYPART"
</meta>
<composite-id name="comp_id" class="com.invisioninc.hibernate.data.DtOutletDaypartPK">
<meta attribute="class-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<!-- bi-directional many-to-one association to DtOutlet -->
<key-many-to-one
name="dtOutlet"
class="com.invisioninc.hibernate.data.DtOutlet"
>
<meta attribute="field-description">
@hibernate.many-to-one
column="OUTLET_CD""
</meta>
<column name="OUTLET_CD" />
</key-many-to-one>
<!-- bi-directional many-to-one association to DtDaypart -->
<key-many-to-one
name="dtDaypart"
class="com.invisioninc.hibernate.data.DtDaypart"
>
<meta attribute="field-description">
@hibernate.many-to-one
column="DAYPART_ID""
</meta>
<column name="DAYPART_ID" />
</key-many-to-one>
</composite-id>
<property
name="defaultInd"
type="java.lang.String"
column="DEFAULT_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="DEFAULT_IND"
length="1"
not-null="true"
</meta>
</property>
<property
name="auditDate"
type="java.sql.Timestamp"
column="AUDIT_DATE"
not-null="true"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="AUDIT_DATE"
length="7"
not-null="true"
</meta>
</property>
<property
name="auditUser"
type="int"
column="AUDIT_USER"
not-null="true"
length="6"
>
<meta attribute="field-description">
@hibernate.property
column="AUDIT_USER"
length="6"
not-null="true"
</meta>
</property>
<property
name="daysAndTimes"
type="java.lang.String"
column="DAYS_AND_TIMES"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="DAYS_AND_TIMES"
length="100"
</meta>
</property>
<property
name="listOrder"
type="java.math.BigDecimal"
column="LIST_ORDER"
not-null="true"
length="4"
>
<meta attribute="field-description">
@hibernate.property
column="LIST_ORDER"
length="4"
not-null="true"
</meta>
</property>
<property
name="activeInd"
type="java.lang.String"
column="ACTIVE_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="ACTIVE_IND"
length="1"
not-null="true"
</meta>
</property>
<property
name="stewActiveInd"
type="java.lang.String"
column="STEW_ACTIVE_IND"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="STEW_ACTIVE_IND"
length="1"
not-null="true"
</meta>
</property>
<!-- associations -->
</class>
</hibernate-mapping>
and the code generated from that using the new jars:
Code:
package com.invisioninc.hibernate.data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/**
* @hibernate.class
* table="DT_OUTLET_DAYPART"
*
*/
public class DtOutletDaypart implements Serializable {
/** identifier field */
private com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id;
/** persistent field */
private String defaultInd;
/** persistent field */
private Date auditDate;
/** persistent field */
private int auditUser;
/** nullable persistent field */
private String daysAndTimes;
/** persistent field */
private BigDecimal listOrder;
/** persistent field */
private String activeInd;
/** persistent field */
private String stewActiveInd;
/** full constructor */
public DtOutletDaypart(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id, String defaultInd, Date auditDate, int auditUser, String daysAndTimes, BigDecimal listOrder, String activeInd, String stewActiveInd) {
this.comp_id = comp_id;
this.defaultInd = defaultInd;
this.auditDate = auditDate;
this.auditUser = auditUser;
this.daysAndTimes = daysAndTimes;
this.listOrder = listOrder;
this.activeInd = activeInd;
this.stewActiveInd = stewActiveInd;
}
/** default constructor */
public DtOutletDaypart() {
}
/** minimal constructor */
public DtOutletDaypart(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id, String defaultInd, Date auditDate, int auditUser, BigDecimal listOrder, String activeInd, String stewActiveInd) {
this.comp_id = comp_id;
this.defaultInd = defaultInd;
this.auditDate = auditDate;
this.auditUser = auditUser;
this.listOrder = listOrder;
this.activeInd = activeInd;
this.stewActiveInd = stewActiveInd;
}
public com.invisioninc.hibernate.data.DtOutletDaypartPK getComp_id() {
return this.comp_id;
}
public void setComp_id(com.invisioninc.hibernate.data.DtOutletDaypartPK comp_id) {
this.comp_id = comp_id;
}
/**
* @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.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="STEW_ACTIVE_IND"
* length="1"
* not-null="true"
*
*/
public String getStewActiveInd() {
return this.stewActiveInd;
}
public void setStewActiveInd(String stewActiveInd) {
this.stewActiveInd = stewActiveInd;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof DtOutletDaypart) ) return false;
DtOutletDaypart castOther = (DtOutletDaypart) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
The difference is in the getter for the composite id does not have the metadata for the hibernate.id in the java class. With the old jars the meta data in the hbm xml file was copied into the java class. So it looks like the hbm.xml file is correct with both the new and old jars but hbm2java is behaving differently. I am still using the the same hibernate-tools.jar for both instances since I did not see a new copy of that jar.
Here is the error I get during the ant build:
Code:
BUILD FAILED
file:c:/cvsrepos/datatest/build.xml:377: Unexpected error
at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:123)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:193)
at org.apache.tools.ant.Task.perform(Task.java:341)
at org.apache.tools.ant.Target.execute(Target.java:309)
at org.apache.tools.ant.Target.performTasks(Target.java:336)
at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
at org.apache.tools.ant.Main.runBuild(Main.java:609)
at org.apache.tools.ant.Main.start(Main.java:196)
at org.apache.tools.ant.Main.main(Main.java:235)
Caused by: file:c:/cvsrepos/datatest/build.xml:377: XDoclet failed.
at xdoclet.DocletTask.start(DocletTask.java:467)
at xjavadoc.ant.XJavadocTask.execute(XJavadocTask.java:110)
... 9 more
Caused by: xdoclet.XDocletException: Class com.invisioninc.hibernate.data.DtOutletDaypart misses ID property
at xdoclet.modules.hibernate.HibernateTagsHandler.hasCompositeId_Impl(HibernateTagsHandler.java:482)
at xdoclet.modules.hibernate.HibernateTagsHandler.ifHasPrimitiveId(HibernateTagsHandler.java:153)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at xdoclet.template.TemplateEngine.invoke(TemplateEngine.java:635)
at xdoclet.template.TemplateEngine.invokeMethod(TemplateEngine.java:561)
at xdoclet.template.TemplateEngine.invokeBlockMethod(TemplateEngine.java:959)
at xdoclet.template.TemplateEngine.handleBlockTag(TemplateEngine.java:926)
at xdoclet.template.TemplateEngine.handleTag(TemplateEngine.java:466)
at xdoclet.template.TemplateEngine.generate(TemplateEngine.java:347)
at xdoclet.template.TemplateEngine.start(TemplateEngine.java:414)
at xdoclet.TemplateSubTask.startEngine(TemplateSubTask.java:560)
at xdoclet.TemplateSubTask.generateForClass(TemplateSubTask.java:767)
at xdoclet.TemplateSubTask.startProcessPerClass(TemplateSubTask.java:667)
at xdoclet.TemplateSubTask.startProcess(TemplateSubTask.java:594)
at xdoclet.XmlSubTask.startProcess(XmlSubTask.java:198)
at xdoclet.modules.hibernate.HibernateSubTask.execute(HibernateSubTask.java:123)
at xdoclet.XDocletMain.start(XDocletMain.java:48)
at xdoclet.DocletTask.start(DocletTask.java:464)
... 10 more
Thanks for any help.
Craig