[ http://jira.andromda.org/browse/HIB-138?page=history ]
     
Work on HIB-138 started by Carlos Cuenca

> entity.equals doesn't work correct with proxies
> -----------------------------------------------
>
>          Key: HIB-138
>          URL: http://jira.andromda.org/browse/HIB-138
>      Project: Hibernate Cartridge
>         Type: Bug
>     Versions: 3.1M1
>     Reporter: Patrik Jurica
>     Assignee: Carlos Cuenca
>     Priority: Minor
>  Attachments: hibernate.java.vm
>
> Generated Java code for entity.equals(Object object) doesn't work, when the 
> equaled paramater is a CGLIB proxy, beacuse "that.$attribute.name" is used. 
> But "that.$attribute.name" can be null in the proxy object. 
> "that.${attribute.getterName}()" must be used instead.
> The corrected templates\hibernate\hibernate.java.vm follows:
> ##
> ##  This macro will render the equals() method
> ##  If an entity is rendered, the attributeSet consists of the identifiers,
> ##  if an value type is renderer, the attributeSet consists of all attributes
> ##
> #macro (renderEqualsMethod $class $className $attributeSet)
>     public boolean equals(Object object)
>     {
> #if ($attributeSet.empty)
>         return super.equals(object);
> #else
>         if (this == object)
>         {
>             return true;
>         }
>         if (!(object instanceof $className))
>         {
>             return false;
>         }
>         final $className that = ($className)object;
> #foreach ($attribute in $attributeSet)
> #set ($idType = $attribute.type)
> #if ($idType.primitive)
>         if (this.$attribute.name != that.${attribute.getterName}())
>         {
>             return false;
>         }
> #elseif ($idType.arrayType)
>         if (!java.util.Arrays.equals(this.$attribute.name, 
> that.${attribute.getterName}()))
>         {
>             return false;
>         }
> #else
>         if (this.$attribute.name == null || that.${attribute.getterName}() == 
> null || !this.${attribute.name}.equals(that.${attribute.getterName}()))
>         {
>             return false;
>         }
> #end
> #end
>         return true;
> #end
>     }
> #end
> ##
> ##  This macro will render the hashCode() method
> ##  If an entity is rendered, the attributeSet consists of the identifiers,
> ##  if an value type is renderer, the attributeSet consists of all attributes
> ##
> #macro (renderHashCodeMethod $class $attributeSet)
>     public int hashCode()
>     {
> #if ($attributeSet.empty)
>         return super.hashCode();
> #else
> #if ($class.generalization)
>         int hashCode = super.hashCode();
> #else
>         int hashCode = 0;
> #end
> #foreach ($attribute in $attributeSet)
> #set ($attrType = $attribute.type)
> #if  ($attribute.getterSetterTypeName == "boolean")
>         hashCode = 29 * hashCode + (${attribute.name} ? 1 : 0);
> #elseif ($attrType.arrayType)
>         // arrays are not part of the hashCode calculation
> #elseif ($attrType.primitive)
>         hashCode = 29 * hashCode + (int)${attribute.name};
> #else
>         hashCode = 29 * hashCode + (${attribute.name} == null ? 0 : 
> ${attribute.name}.hashCode());
> #end## if
> #end## foreach
>         return hashCode;
> #end## $attributeSet.empty
>     }
> #end




-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information

Reply via email to