Bug 441546 - Foreign Key attribute when used in JoinColumn generates wrong DDL statement
             Fixed NoSQL Test Failure.

Reviewed By: Lukas Jungmann
diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/MappingAccessor.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/MappingAccessor.java
index f9d2268..0bed092 100644
--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/MappingAccessor.java
+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/accessors/mappings/MappingAccessor.java
@@ -1889,7 +1889,7 @@ protected void processForeignKeyRelationship(ForeignReferenceMapping mapping, Li
         Map<DatabaseField, DatabaseField> fields = new HashMap<DatabaseField, DatabaseField>();
         List<String> sourceFields = new ArrayList<String>();
         List<String> targetFields = new ArrayList<String>();
-        String targetTableName = null;
+        DatabaseTable targetTable = null;
         
         // Build our fk->pk associations.
         for (JoinColumnMetadata joinColumn : joinColumns) {
@@ -1910,8 +1910,8 @@ protected void processForeignKeyRelationship(ForeignReferenceMapping mapping, Li
             fields.put(fkField, pkField);
             sourceFields.add(fkField.getName());
             targetFields.add(pkField.getName());
-            if (targetTableName == null) {
-                targetTableName = pkField.getTableName();
+            if (targetTable == null) {
+                targetTable = pkField.getTable();
             }
             allReadOnly = allReadOnly && fkField.isReadOnly();
         }
@@ -1947,7 +1947,7 @@ protected void processForeignKeyRelationship(ForeignReferenceMapping mapping, Li
         // the spec case (on the source table) and our extended support when
         // the fk's are on the target table as well.
         if (foreignKey != null) {
-            foreignKey.process(foreignKeyTable, sourceFields, targetFields, targetTableName);
+            foreignKey.process(foreignKeyTable, sourceFields, targetFields, targetTable);
         }
     }
 
diff --git a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/columns/ForeignKeyMetadata.java b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/columns/ForeignKeyMetadata.java
index 0df4770..63c8cfc 100644
--- a/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/columns/ForeignKeyMetadata.java
+++ b/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/metadata/columns/ForeignKeyMetadata.java
@@ -173,7 +173,7 @@ public void process(DatabaseTable table) {
      * INTERNAL:
      * Process this JPA metadata into an EclipseLink ForeignKeyConstraint.
      */
-    public void process(DatabaseTable table, List<String> sourceFields, List<String> targetFields, String targetTableName) {
+    public void process(DatabaseTable table, List<String> sourceFields, List<String> targetFields, DatabaseTable targetTable) {
         if (! isProviderDefaultConstraintMode()) {
             ForeignKeyConstraint foreignKeyConstraint = new ForeignKeyConstraint();
             foreignKeyConstraint.setName(getName());
@@ -190,8 +190,8 @@ public void process(DatabaseTable table, List<String> sourceFields, List<String>
                 if (targetFields != null) {
                     foreignKeyConstraint.setTargetFields(targetFields);
                 }
-                if (targetTableName != null) {
-                    foreignKeyConstraint.setTargetTable(targetTableName);
+                if (targetTable != null) {
+                    foreignKeyConstraint.setTargetTable(targetTable.getName());
                 }
             }
             table.addForeignKeyConstraint(foreignKeyConstraint);