From ab9d17f12e6e5bc2b784d7f4e5b4d45b47aac9b6 Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Tue, 10 Mar 2009 17:37:57 +0000 Subject: [PATCH] OPENJPA-679: fix ReverseMappingTool problem git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@752178 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/meta/ClassMapping.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java index d8a03355e..9d2e2b65a 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java @@ -35,7 +35,6 @@ import org.apache.openjpa.enhance.Reflection; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy; -import org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy; import org.apache.openjpa.jdbc.schema.Column; import org.apache.openjpa.jdbc.schema.ColumnIO; import org.apache.openjpa.jdbc.schema.ForeignKey; @@ -54,10 +53,10 @@ import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.ValueMetaData; import org.apache.openjpa.util.ApplicationIds; +import org.apache.openjpa.util.ImplHelper; import org.apache.openjpa.util.InternalException; import org.apache.openjpa.util.MetaDataException; import org.apache.openjpa.util.OpenJPAId; -import org.apache.openjpa.util.ImplHelper; /** * Specialization of metadata for relational databases. @@ -89,7 +88,6 @@ public class ClassMapping // maps columns to joinables private final Map _joinables = Collections.synchronizedMap(new HashMap()); - private boolean redoPrimaryKeyColumns = false; /** * Constructor. Supply described type and owning repository. @@ -418,18 +416,15 @@ public class ClassMapping */ public Column[] getPrimaryKeyColumns() { if (getIdentityType() == ID_APPLICATION && isMapped()) { - if (_cols.length == 0 || redoPrimaryKeyColumns) { + if (_cols.length == 0) { FieldMapping[] pks = getPrimaryKeyFieldMappings(); Collection cols = new ArrayList(pks.length); Column[] fieldCols; for (int i = 0; i < pks.length; i++) { fieldCols = pks[i].getColumns(); if (fieldCols.length == 0) { - // some pk columns depends on fk. At this moment, - // the fk may not contain complete information. - // need to redo the primary key again later on - redoPrimaryKeyColumns = true; - continue; + _cols = new Column[0]; + return _cols; } for (int j = 0; j < fieldCols.length; j++) cols.add(fieldCols[j]); @@ -835,8 +830,11 @@ public class ClassMapping FieldMapping[] fms = getFieldMappings(); for (int i = 0; i < fms.length; i++) { if (fms[i].getDefiningMetaData() == this) { - if (fms[i].getForeignKey() != null && - fms[i].getStrategy() instanceof RelationFieldStrategy) { + boolean fill = getMappingRepository().getMappingDefaults(). + defaultMissingInfo(); + ForeignKey fk = fms[i].getForeignKey(); + if (fill && fk != null && + fk.getPrimaryKeyColumns().length == 0) { // set resolve mode to force this field mapping to be // resolved again. The need to resolve again occurs when // a primary key is a relation field with the foreign key @@ -845,11 +843,10 @@ public class ClassMapping // resolveNonRelationMapping. Since it is a relation // field, the foreign key will be constructed. However, // the primary key of the parent entity may not have been - // resolved yet, resulting in missing informaiton in the fk + // resolved yet, resulting in missing information in the fk fms[i].setResolve(MODE_META); - - // set strategy to null to force fk to be re-constructed - fms[i].setStrategy(null, false); + if (fms[i].getStrategy() != null) + fms[i].getStrategy().map(false); } fms[i].resolve(MODE_MAPPING); }