[hibernate-commits] Hibernate SVN: r14777 - in annotations/trunk/src: test/org/hibernate/test/annotations and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jun 18 13:47:30 EDT 2008


Author: hardy.ferentschik
Date: 2008-06-18 13:47:30 -0400 (Wed, 18 Jun 2008)
New Revision: 14777

Added:
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A_PK.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/B.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/C.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassA.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassB.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassC.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassD.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D_PK.java
   annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java
Modified:
   annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
Log:
ANN-722 / ANN-730
* Added test cases attached to the Jira issues 
* Reimplemented processFkSecondPassInOrder() in AnnotationConfiguration using a recursive algorithm for ordering FKSecondPass instances

Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2008-06-18 14:46:01 UTC (rev 14776)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -9,7 +9,6 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -18,9 +17,7 @@
 import java.util.Properties;
 import java.util.ResourceBundle;
 import java.util.Set;
-import java.util.SortedSet;
 import java.util.StringTokenizer;
-import java.util.TreeSet;
 import javax.persistence.Entity;
 import javax.persistence.MappedSuperclass;
 
@@ -57,9 +54,10 @@
 
 /**
  * Similar to the {@link Configuration} object but handles EJB3 and Hibernate
- * specific annotations as a metadata facility
+ * specific annotations as a metadata facility.
  *
  * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
  */
 @SuppressWarnings({"unchecked", "serial"})
 public class AnnotationConfiguration extends Configuration {
@@ -106,7 +104,7 @@
 	protected List<XClass> orderAndFillHierarchy(List<XClass> original) {
 		//TODO remove embeddable
 		List<XClass> copy = new ArrayList<XClass>( original );
-		//for each class, copy all the relevent hierarchy
+		//for each class, copy all the relevant hierarchy
 		for (XClass clazz : original) {
 			XClass superClass = clazz.getSuperclass();
 			while ( superClass != null && !reflectionManager.equals( superClass, Object.class ) && !copy.contains( superClass ) ) {
@@ -384,36 +382,89 @@
 		}
 	}
 
+	/**
+	 * Processes FKSecondPass instances trying to resolve any
+	 * graph circularity (ie PK made of a many to one linking to
+	 * an entity having a PK made of a ManyToOne ...).
+	 */
 	private void processFkSecondPassInOrder() {
 		log.debug( "processing fk mappings (*ToOne and JoinedSubclass)" );
-		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
-		 * an entity having a PK made of a ManyToOne ...
+		List<FkSecondPass> fkSecondPasses = getFKSecondPassesOnly();
+		
+		if (fkSecondPasses.size() == 0) {
+			return; // nothing to do here
+		}
+		
+		// split FkSecondPass instances into primary key and non primary key FKs.
+		// While doing so build a map of class names to FkSecondPass instances depending on this class.
+		Map<String, Set<FkSecondPass>> isADependencyOf = new HashMap<String, Set<FkSecondPass>>();
+		List endOfQueueFkSecondPasses = new ArrayList( fkSecondPasses.size() );
+		for (FkSecondPass sp : fkSecondPasses) {
+			if ( sp.isInPrimaryKey() ) {
+				String referenceEntityName = sp.getReferencedEntityName();
+				PersistentClass classMapping = getClassMapping( referenceEntityName );
+				String dependentTable = classMapping.getTable().getQuotedName();
+				if ( !isADependencyOf.containsKey( dependentTable ) ) {
+					isADependencyOf.put( dependentTable, new HashSet<FkSecondPass>() );
+				}
+				isADependencyOf.get( dependentTable ).add( sp );
+			}
+			else {
+				endOfQueueFkSecondPasses.add( sp );
+			}
+		}
+		
+		// using the isADependencyOf map we order the FkSecondPass recursively instances into the right order for processing
+		List<FkSecondPass> orderedFkSecondPasses = new ArrayList( fkSecondPasses.size() );
+		for (String tableName : isADependencyOf.keySet()) {
+			buildRecursiveOrderedFkSecondPasses(orderedFkSecondPasses, isADependencyOf, tableName, tableName);
+		}
+		
+		// process the ordered FkSecondPasses
+		for ( FkSecondPass sp : orderedFkSecondPasses ) {
+			sp.doSecondPass( classes );
+		}
+
+		processEndOfQueue(endOfQueueFkSecondPasses);
+	}
+
+	private void processEndOfQueue(List endOfQueueFkSecondPasses) {
+		/*
+		 * If a second pass raises a recoverableException, queue it for next round
+		 * stop of no pass has to be processed or if the number of pass to processes
+		 * does not diminish between two rounds.
+		 * If some failing pass remain, raise the original exception
 		 */
-		SortedSet<FkSecondPass> fkSecondPasses = new TreeSet<FkSecondPass>(
-				new Comparator<FkSecondPass>() {
-					//The comparator implementation has to respect the compare=0 => equals() = true for sets
-					public int compare(FkSecondPass f1, FkSecondPass f2) {
-						int compare = f1.getValue().getTable().getQuotedName().compareTo(
-								f2.getValue().getTable().getQuotedName()
-						);
-						if ( compare == 0 ) {
-							//same table, we still need to differenciate true equality
-							if ( f1.hashCode() < f2.hashCode() ) {
-								compare = -1;
-							}
-							else if ( f1.hashCode() == f2.hashCode() ) {
-								compare = 0;
-							}
-							else {
-								compare = 1;
-							}
-						}
-						return compare;
-					}
+		boolean stopProcess = false;
+		RuntimeException originalException = null;
+		while ( ! stopProcess ) {
+			List failingSecondPasses = new ArrayList();
+			Iterator it = endOfQueueFkSecondPasses.listIterator();
+			while ( it.hasNext() ) {
+				final SecondPass pass = (SecondPass) it.next();
+				try {
+					pass.doSecondPass( classes );
 				}
-		);
+				catch (RecoverableException e) {
+					failingSecondPasses.add( pass );
+					if (originalException == null) originalException = (RuntimeException) e.getCause();
+				}
+			}
+			stopProcess = failingSecondPasses.size() == 0 || failingSecondPasses.size() == endOfQueueFkSecondPasses.size();
+			endOfQueueFkSecondPasses = failingSecondPasses;
+		}
+		if (endOfQueueFkSecondPasses.size() > 0) {
+			throw originalException;
+		}
+	}
+
+	/**
+	 * @return Returns a list of all <code>secondPasses</code> instances which are a instance of
+	 * <code>FkSecondPass</code>.
+	 */
+	private List<FkSecondPass> getFKSecondPassesOnly() {
+		Iterator iter = secondPasses.iterator();
+		List<FkSecondPass> fkSecondPasses = new ArrayList<FkSecondPass>(secondPasses.size());
 		while ( iter.hasNext() ) {
 			SecondPass sp = (SecondPass) iter.next();
 			//do the second pass of fk before the others and remove them
@@ -422,90 +473,45 @@
 				iter.remove();
 			}
 		}
-		if ( fkSecondPasses.size() > 0 ) {
-			Map<String, Set<String>> isADependencyOf = new HashMap<String, Set<String>>();
-			List orderedFkSecondPasses = new ArrayList( fkSecondPasses.size() );
-			List endOfQueueFkSecondPasses = new ArrayList( fkSecondPasses.size() );
-			List orderedTable = new ArrayList( fkSecondPasses.size() );
-			Iterator it = fkSecondPasses.iterator();
-			while ( it.hasNext() ) {
-				FkSecondPass sp = (FkSecondPass) it.next();
-				String referenceEntityName = sp.getReferencedEntityName();
-				PersistentClass classMapping = getClassMapping( referenceEntityName );
-				if ( sp.isInPrimaryKey() ) {
-					String dependentTable = classMapping.getTable().getQuotedName();
-					if ( !isADependencyOf.containsKey( dependentTable ) ) {
-						isADependencyOf.put( dependentTable, new HashSet<String>() );
-					}
-					String table = sp.getValue().getTable().getQuotedName();
-					isADependencyOf.get( dependentTable ).add( table );
-					int beAfter = orderedTable.indexOf( dependentTable );
-					int beBefore = orderedFkSecondPasses.size();
-					Set<String> dependencies = isADependencyOf.get( table );
-					if ( dependencies != null ) {
-						for (String tableDep : dependencies) {
-							//for each declared dependency take the lowest index
-							int index = orderedTable.indexOf( tableDep );
-							//index = -1 when we have a self dependency
-							beBefore = index != -1 && index < beBefore ? index : beBefore;
-						}
-					}
-					int currentIndex = orderedTable.indexOf( table );
-					if ( beBefore < beAfter ||
-							( currentIndex != -1 && ( currentIndex < beAfter || currentIndex > beBefore ) )
-							) {
-						StringBuilder sb = new StringBuilder(
-								"Foreign key circularity dependency involving the following tables: "
-						);
-						//TODO deduplicate tables
-						sb.append( table );
-						if ( beAfter > -1 ) sb.append( ", " ).append( dependentTable );
-						if ( beBefore < orderedFkSecondPasses.size() ) {
-							sb.append( ", " ).append( orderedTable.get( beBefore ) );
-						}
-						throw new AnnotationException( sb.toString() );
-					}
-					currentIndex = currentIndex == -1 ? beBefore : currentIndex;
-					orderedTable.add( currentIndex, table );
-					orderedFkSecondPasses.add( currentIndex, sp );
-				}
-				else {
-					endOfQueueFkSecondPasses.add( sp );
-				}
-			}
-			it = orderedFkSecondPasses.listIterator();
-			while ( it.hasNext() ) {
-				( (SecondPass) it.next() ).doSecondPass( classes );
-			}
+		return fkSecondPasses;
+	}
 
-			/*
-			 * If a second pass raises a recoverableException, queue it for next round
-			 * stop of no pass has to be processed or if the number of pass to processes
-			 * does not diminish between two rounds.
-			 * If some failing pass remain, raise the original exception
-			 */
-			boolean stopProcess = false;
-			RuntimeException originalException = null;
-			while ( ! stopProcess ) {
-				List failingSecondPasses = new ArrayList();
-				it = endOfQueueFkSecondPasses.listIterator();
-				while ( it.hasNext() ) {
-					final SecondPass pass = (SecondPass) it.next();
-					try {
-						pass.doSecondPass( classes );
-					}
-					catch (RecoverableException e) {
-						failingSecondPasses.add( pass );
-						if (originalException == null) originalException = (RuntimeException) e.getCause();
-					}
-				}
-				stopProcess = failingSecondPasses.size() == 0 || failingSecondPasses.size() == endOfQueueFkSecondPasses.size();
-				endOfQueueFkSecondPasses = failingSecondPasses;
+	/**
+	 * Recursively builds a list of FkSecondPass instances ready to be processed in this order.
+	 * Checking all dependencies recursively seems quite expensive, but the original code just relied 
+	 * on some sort of table name sorting which failed in certain circumstances.
+	 * 
+	 * @param orderedFkSecondPasses The list containing the <code>FkSecondPass<code> instances ready 
+	 * for processing.
+	 * @param isADependencyOf Our lookup data structure to determine dependencies between tables
+	 * @param startTable Table name to start recursive algorithm.
+	 * @param currentTable The current table name used to check for 'new' dependencies.
+	 * 
+	 * @see ANN-722 ANN-730
+	 */
+	private void buildRecursiveOrderedFkSecondPasses(
+			List orderedFkSecondPasses,
+			Map<String, Set<FkSecondPass>> isADependencyOf, String startTable, String currentTable) {
+
+		Set<FkSecondPass> dependencies = isADependencyOf.get(currentTable);
+		
+		// bottom out
+		if (dependencies == null || dependencies.size() == 0) {
+			return;
+		}
+		
+		for (FkSecondPass sp : dependencies) {
+			String dependentTable = sp.getValue().getTable().getQuotedName();
+			if (dependentTable.compareTo(startTable) == 0) {
+				StringBuilder sb = new StringBuilder(
+						"Foreign key circularity dependency involving the following tables: ");
+				throw new AnnotationException(sb.toString());
 			}
-			if (endOfQueueFkSecondPasses.size() > 0) {
-				throw originalException;
+			buildRecursiveOrderedFkSecondPasses(orderedFkSecondPasses, isADependencyOf, startTable, dependentTable);
+			if (!orderedFkSecondPasses.contains(sp)) {
+				orderedFkSecondPasses.add(0, sp);
 			}
-		}
+		}		
 	}
 
 	private void processArtifactsOfType(String artifact) {

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,25 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at Entity
+public class A {
+	private A_PK id;
+
+	@EmbeddedId
+	public A_PK getId() {
+		return id;
+	}
+
+	public void setId(A_PK id) {
+		this.id = id;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A_PK.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A_PK.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A_PK.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,26 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import java.io.Serializable;
+
+import javax.persistence.ManyToOne;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at SuppressWarnings("serial")
+public class A_PK implements Serializable {
+	public D d;
+
+	@ManyToOne
+	public D getD() {
+		return d;
+	}
+
+	public void setD(D d) {
+		this.d = d;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/A_PK.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/B.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/B.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/B.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,28 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at Entity
+ at Inheritance(strategy = InheritanceType.JOINED)
+public class B {
+	@Id
+	private int id;
+
+	public int getId() {
+		return id;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/B.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/C.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/C.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/C.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,14 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Entity;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at Entity
+public class C extends B {
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/C.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassA.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassA.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassA.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,33 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+/**
+ * Test entities ANN-730.
+ * 
+ * @author Hardy Ferentschik
+ * 
+ */
+ at Entity
+ at Table(name = "class_a")
+ at Inheritance(strategy = InheritanceType.JOINED)
+public class ClassA {
+
+	private int id;
+
+	@Id
+	@Column(name = "id")
+	public int getId() {
+		return id;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassA.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassB.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassB.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassB.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,18 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+/**
+ * Test entities ANN-730.
+ * 
+ * @author Hardy Ferentschik
+ * 
+ */
+ at Entity
+ at Table(name = "class_b")
+ at PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
+public class ClassB extends ClassA {
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassB.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassC.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassC.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassC.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,18 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+/**
+ * Test entities ANN-730.
+ * 
+ * @author Hardy Ferentschik
+ * 
+ */
+ at Entity
+ at Table(name = "class_c")
+ at PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
+public class ClassC extends ClassB {
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassC.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassD.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassD.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassD.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,18 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+/**
+ * Test entities ANN-730.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at Entity
+ at Table(name = "class_1d")
+ at PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
+public class ClassD extends ClassC {
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/ClassD.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,25 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at Entity
+public class D {
+	private D_PK id;
+
+	@EmbeddedId
+	public D_PK getId() {
+		return id;
+	}
+
+	public void setId(D_PK id) {
+		this.id = id;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D_PK.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D_PK.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D_PK.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,26 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import java.io.Serializable;
+
+import javax.persistence.ManyToOne;
+
+/**
+ * Test entities ANN-722.
+ * 
+ * @author Hardy Ferentschik
+ *
+ */
+ at SuppressWarnings("serial")
+public class D_PK implements Serializable{
+	private C c;
+	
+	@ManyToOne
+	public C getC() {
+		return c;
+	}
+
+	public void setC(C c) {
+		this.c = c;
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/D_PK.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java	2008-06-18 17:47:30 UTC (rev 14777)
@@ -0,0 +1,67 @@
+// $Id:$
+package org.hibernate.test.annotations.fkcircularity;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.dialect.SQLServerDialect;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test case for ANN-722 and ANN-730.
+ * 
+ * @author Hardy Ferentschik
+ */
+public class FkCircularityTest extends TestCase {
+
+	private Logger log = LoggerFactory.getLogger(FkCircularityTest.class);
+
+	public void testJoinedSublcassesInPK() {
+		try {
+			AnnotationConfiguration config = new AnnotationConfiguration();
+			config.addAnnotatedClass(A.class);
+			config.addAnnotatedClass(B.class);
+			config.addAnnotatedClass(C.class);
+			config.addAnnotatedClass(D.class);
+			config.buildSessionFactory();
+			String[] schema = config
+					.generateSchemaCreationScript(new SQLServerDialect());
+			for (String s : schema) {
+				log.debug(s);
+			}
+			log.debug("success");
+		} catch (Exception e) {
+			StringWriter writer = new StringWriter();
+			e.printStackTrace(new PrintWriter(writer));
+			log.debug(writer.toString());
+			fail(e.getMessage());
+		}
+	}
+
+	public void testDeepJoinedSuclassesHierachy() {
+		try {
+			AnnotationConfiguration config = new AnnotationConfiguration();
+			config.addAnnotatedClass(ClassA.class);
+			config.addAnnotatedClass(ClassB.class);
+			config.addAnnotatedClass(ClassC.class);
+			config.addAnnotatedClass(ClassD.class);
+			config.buildSessionFactory();
+			String[] schema = config
+					.generateSchemaCreationScript(new HSQLDialect());
+			for (String s : schema) {
+				log.debug(s);
+			}
+			log.debug("success");
+		} catch (Exception e) {
+			StringWriter writer = new StringWriter();
+			e.printStackTrace(new PrintWriter(writer));
+			log.debug(writer.toString());
+			fail(e.getMessage());
+		}
+	}
+}
\ No newline at end of file


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java
___________________________________________________________________
Name: svn:keywords
   + Id




More information about the hibernate-commits mailing list