Hi,
I'm trying to customize my equals() and hasCode() methods so that it is based on the columns that have a unique constraint. So I was able to actually get part of it to work.
I defined the following in my ant target, within the hbm2java task.
Code:
<property key="hibernatetool.myequals.toolclass"
value="org.hibernate.tool.hbm2x.pojo.MyPojoClass"/>
Here's my PojoEqualsHashcode.ftl
------------------------------------------------------------
<#if
myequals.isUniqueConstraintExist(pojo) && !clazz.superclass?exists>
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof ${pojo.getDeclarationName()}) ) return false;
${pojo.getDeclarationName()} castOther = (
${pojo.getDeclarationName()} ) other;
return
${myequals.generateEquals(pojo, "this", "castOther", jdk5)};
}
public int hashCode() {
int result = 17;
<#foreach property in pojo.getAllPropertiesIterator()>
${pojo.generateHashCode(property, "result", "this", jdk5)}
</#foreach> return result;
}
</#if>
----------------------------------------------------------------
If I don't use myequals in the <#if ...> statement this whole thing works. But if I used it like shown above, I get the following error.
Code:
ERROR -
[hibernatetool] Expression myequals.isUniqueConstraintExist is undefined on
line 1, column 6 in pojo/PojoEqualsHashcode.ftl.
[hibernatetool] The problematic instruction:
[hibernatetool] ----------
[hibernatetool] ==> if myequals.isUniqueConstraintExist(pojo) && !clazz.superclass?exists [on line 1, column 1 in pojo/PojoEqualsHashcode.ftl]
[hibernatetool] in include "PojoEqualsHashcode.ftl" [on line 16, column 1 in
pojo/Pojo.ftl]
[hibernatetool] ----------
Thanks in advance.
Budyanto