The following issue has been updated: Updater: Andrew Stevens (mailto:[EMAIL PROTECTED]) Date: Mon, 14 Feb 2005 4:04 PM Changes: Version changed to 1.2.2 Version changed to 1.2.1 --------------------------------------------------------------------- For a full history of the issue, see:
http://opensource.atlassian.com/projects/xdoclet/browse/XDT-941?page=history --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/xdoclet/browse/XDT-941 Here is an overview of the issue: --------------------------------------------------------------------- Key: XDT-941 Summary: hashcode bug in ValueObject when Relation is included Type: Bug Status: Open Priority: Major Original Estimate: Unknown Time Spent: Unknown Remaining: Unknown Project: XDoclet Components: EJB Module Versions: 1.2 1.2.1 1.2.2 Assignee: xdoclet-devel (Use for new issues) Reporter: Sebastian Hennebrueder Created: Thu, 24 Jun 2004 5:19 AM Updated: Mon, 14 Feb 2005 4:04 PM Environment: Windows 2000, eclipse 3.0 RC1, Myeclipse 3.08 Description: When ValueObject of a entity EJB includes a 1:n relation to a second entity EJB the hashCode of the generated Value Object changes each time it is calculated. ###### Reason is: Bad calculation of hashcode The following happens: 1) internally the relation ValueObject is hold as a Collection. The getter returns a new Array public de.laliluna.test.AttributeValue[] getAttributeValues() { return (test.AttributeValue[])this.AttributeValues.toArray(new test.AttributeValue[AttributeValues.size()]); } 2) hashcode is calculated like this result = 37*result + ((this.getAttributeValues() != null) ? this.getAttributeValues().hashCode() : 0); 3) hashCode of a new Array is allways different. Take the following code to test it: private void testArrayHashCode(){ Collection c = new ArrayList(); for (int i = 0; i< 10 ; i++){ Object o[] = c.toArray(); System.out.println(o.hashCode()); } } ###### Solution is: when there is a 1:n relation the hashcode for the ValuObject should be calculated like AttributeValue attributeValue[]= this.getAttributeValues(); for (int i = 0; i < attributeValue.length; i++) { result = 37*result + ((attributeValue[i]!= null) ? attributeValue[i].hashCode() : 0); } ###### References Effektiv Java Programmieren, Joshua Bloch http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&frame=right&th=da63e9665f3f9e16&seekm=40b9fb89%240%2431679%24afc38c87%40news.optusnet.com.au#link1 Hope I could help Sebastian http://www.laliluna.de --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/xdoclet/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ xdoclet-devel mailing list xdoclet-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xdoclet-devel