[hibernate-commits] Hibernate SVN: r14383 - annotations/trunk/src/java/org/hibernate/cfg.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Mar 3 19:22:14 EST 2008


Author: epbernard
Date: 2008-03-03 19:22:13 -0500 (Mon, 03 Mar 2008)
New Revision: 14383

Modified:
   annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
   annotations/trunk/src/java/org/hibernate/cfg/FkSecondPass.java
Log:
ANN-683 avoid hashCode collisions for FKSecondPass (IBM VM reuse the same hashCode between different objects

Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2008-02-29 17:14:51 UTC (rev 14382)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2008-03-04 00:22:13 UTC (rev 14383)
@@ -401,7 +401,6 @@
 								compare = -1;
 							}
 							else if ( f1.hashCode() == f2.hashCode() ) {
-								//FIXME (do not use the hashCode as two objects can have identical hashCode values)
 								compare = 0;
 							}
 							else {

Modified: annotations/trunk/src/java/org/hibernate/cfg/FkSecondPass.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/FkSecondPass.java	2008-02-29 17:14:51 UTC (rev 14382)
+++ annotations/trunk/src/java/org/hibernate/cfg/FkSecondPass.java	2008-03-04 00:22:13 UTC (rev 14383)
@@ -1,6 +1,8 @@
 //$Id: FkSecondPass.java 11650 2007-06-07 16:44:52Z epbernard $
 package org.hibernate.cfg;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.hibernate.mapping.SimpleValue;
 import org.hibernate.mapping.Value;
 
@@ -10,16 +12,44 @@
 public abstract class FkSecondPass implements SecondPass {
 	protected SimpleValue value;
 	protected Ejb3JoinColumn[] columns;
+	/**
+	 * unique counter is needed to differenciate 2 instances of FKSecondPass
+	 * as they are compared.
+	 * Fairly hacky but IBM VM sometimes returns the same hashCode for 2 different objects
+	 * TODO is it doable to rely on the Ejb3JoinColumn names? Not sure at they could be inferred
+	 */
+	private int uniqueCounter;
+	private static AtomicInteger globalCounter = new AtomicInteger();
 
 	public FkSecondPass(SimpleValue value, Ejb3JoinColumn[] columns) {
 		this.value = value;
 		this.columns = columns;
+		this.uniqueCounter = globalCounter.getAndIncrement();
 	}
 
+	public int getUniqueCounter() {
+		return uniqueCounter;
+	}
+
 	public Value getValue() {
 		return value;
 	}
 
+	public boolean equals(Object o) {
+		if ( this == o ) return true;
+		if ( !( o instanceof FkSecondPass ) ) return false;
+
+		FkSecondPass that = (FkSecondPass) o;
+
+		if ( uniqueCounter != that.uniqueCounter ) return false;
+
+		return true;
+	}
+
+	public int hashCode() {
+		return uniqueCounter;
+	}
+
 	public abstract String getReferencedEntityName();
 
 	public abstract boolean isInPrimaryKey();




More information about the hibernate-commits mailing list