Author: gbadner
Date: 2009-05-27 03:16:01 -0400 (Wed, 27 May 2009)
New Revision: 16622
Added:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesHashCodeTest.java
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesIdentityHashCodeTest.java
Modified:
annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/AnnotationConfiguration.java
Log:
JBPAPP-2032 : Upgrading Hibernate from 3.2.x to 3.3.x may cause backward-compatibility
issue due to ANN-683
Modified:
annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
---
annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2009-05-26
17:04:16 UTC (rev 16621)
+++
annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2009-05-27
07:16:01 UTC (rev 16622)
@@ -43,12 +43,8 @@
import org.hibernate.cfg.annotations.Version;
import org.hibernate.cfg.annotations.reflection.EJB3ReflectionManager;
import org.hibernate.cfg.search.SearchConfiguration;
-import org.hibernate.event.PostDeleteEventListener;
-import org.hibernate.event.PostInsertEventListener;
-import org.hibernate.event.PostUpdateEventListener;
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
-import org.hibernate.event.EventListeners;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.PersistentClass;
@@ -75,6 +71,8 @@
public static final String ARTEFACT = "hibernate.mapping.precedence";
public static final String DEFAULT_PRECEDENCE = "hbm, class";
+ public static final String USE_IDENTITY_HASHCODE_TO_COMPARE_FK =
"hibernate.legacy.foreignkey.use_identity_hashcode_to_compare";
+ public static final String DEFAULT_USE_IDENTITY_HASHCODE_TO_COMPARE_FK =
"false";
private Map namedGenerators;
private Map<String, Map<String, Join>> joins;
@@ -94,6 +92,7 @@
private List<CacheHolder> caches;
private List<Document> hbmDocuments; //user ordering matters, hence the list
private String precedence = null;
+ private Boolean isFKComparedUsingIdentityHashCode = null;
private boolean inSecondPass = false;
private transient ReflectionManager reflectionManager;
private boolean isDefaultProcessed = false;
@@ -390,6 +389,13 @@
private void processFkSecondPassInOrder() {
log.debug( "processing fk mappings (*ToOne and JoinedSubclass)" );
+ if ( isFKComparedUsingIdentityHashCode == null ) {
+ isFKComparedUsingIdentityHashCode =
+ Boolean.valueOf( getProperties().getProperty(
+ USE_IDENTITY_HASHCODE_TO_COMPARE_FK,
+ DEFAULT_USE_IDENTITY_HASHCODE_TO_COMPARE_FK )
+ );
+ }
Iterator iter = secondPasses.iterator();
/* We need to process FKSecond pass trying to resolve any
* graph circularity (ie PK made of a many to one linking to
@@ -404,10 +410,10 @@
);
if ( compare == 0 ) {
//same table, we still need to differenciate true equality
- if ( f1.hashCode() < f2.hashCode() ) {
+ if ( getHashCode( f1 ) < getHashCode( f2 ) ) {
compare = -1;
}
- else if ( f1.hashCode() == f2.hashCode() ) {
+ else if ( getHashCode( f1 ) == getHashCode( f2 ) ) {
compare = 0;
}
else {
@@ -416,6 +422,11 @@
}
return compare;
}
+ private int getHashCode(FkSecondPass f) {
+ return isFKComparedUsingIdentityHashCode
+ ? System.identityHashCode( f )
+ : f.hashCode();
+ }
}
);
while ( iter.hasNext() ) {
@@ -725,6 +736,10 @@
this.precedence = precedence;
}
+ public void setFKComparedUsingIdentityHashCode(boolean
isIdentityHashCodeUsedToCompareFK) {
+ this.isFKComparedUsingIdentityHashCode = isIdentityHashCodeUsedToCompareFK;
+ }
+
private static class CacheHolder {
public CacheHolder(String role, String usage, String region, boolean isClass, boolean
cacheLazy) {
this.role = role;
Added:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesHashCodeTest.java
===================================================================
---
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesHashCodeTest.java
(rev 0)
+++
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesHashCodeTest.java 2009-05-27
07:16:01 UTC (rev 16622)
@@ -0,0 +1,46 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.AnnotationConfiguration;
+
+/**
+ * Tests some composite id functionalities setting the property,
+ * AnnotationConfiguration.USE_IDENTITY_HASHCODE_TO_COMPARE_FK, to false.
+ *
+ * @author Gail Badner
+ */
+public class CompositeIdFKComparisonUsesHashCodeTest extends CompositeIdTest {
+ public CompositeIdFKComparisonUsesHashCodeTest(String x) {
+ super( x );
+ }
+
+ @Override
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( AnnotationConfiguration.USE_IDENTITY_HASHCODE_TO_COMPARE_FK,
"false" );
+ super.configure( cfg );
+ }
+}
\ No newline at end of file
Added:
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesIdentityHashCodeTest.java
===================================================================
---
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesIdentityHashCodeTest.java
(rev 0)
+++
annotations/branches/v3_3_1_GA_CP/src/test/org/hibernate/test/annotations/cid/CompositeIdFKComparisonUsesIdentityHashCodeTest.java 2009-05-27
07:16:01 UTC (rev 16622)
@@ -0,0 +1,46 @@
+//$Id: $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.annotations.cid;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.AnnotationConfiguration;
+
+/**
+ * Tests some composite id functionalities setting the property,
+ * AnnotationConfiguration.USE_IDENTITY_HASHCODE_TO_COMPARE_FK, to true.
+ *
+ * @author Gail Badner
+ */
+public class CompositeIdFKComparisonUsesIdentityHashCodeTest extends CompositeIdTest {
+ public CompositeIdFKComparisonUsesIdentityHashCodeTest(String x) {
+ super( x );
+ }
+
+ @Override
+ protected void configure(Configuration cfg) {
+ cfg.setProperty( AnnotationConfiguration.USE_IDENTITY_HASHCODE_TO_COMPARE_FK,
"true" );
+ super.configure( cfg );
+ }
+}
\ No newline at end of file