OPENJPA-679: fix ReverseMappingTool problem

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@752178 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-03-10 17:37:57 +00:00
parent 4506244327
commit ab9d17f12e
1 changed files with 12 additions and 15 deletions

View File

@ -35,7 +35,6 @@ import org.apache.openjpa.enhance.Reflection;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.kernel.JDBCStore;
import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy; 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.Column;
import org.apache.openjpa.jdbc.schema.ColumnIO; import org.apache.openjpa.jdbc.schema.ColumnIO;
import org.apache.openjpa.jdbc.schema.ForeignKey; 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.ClassMetaData;
import org.apache.openjpa.meta.ValueMetaData; import org.apache.openjpa.meta.ValueMetaData;
import org.apache.openjpa.util.ApplicationIds; import org.apache.openjpa.util.ApplicationIds;
import org.apache.openjpa.util.ImplHelper;
import org.apache.openjpa.util.InternalException; import org.apache.openjpa.util.InternalException;
import org.apache.openjpa.util.MetaDataException; import org.apache.openjpa.util.MetaDataException;
import org.apache.openjpa.util.OpenJPAId; import org.apache.openjpa.util.OpenJPAId;
import org.apache.openjpa.util.ImplHelper;
/** /**
* Specialization of metadata for relational databases. * Specialization of metadata for relational databases.
@ -89,7 +88,6 @@ public class ClassMapping
// maps columns to joinables // maps columns to joinables
private final Map _joinables = Collections.synchronizedMap(new HashMap()); private final Map _joinables = Collections.synchronizedMap(new HashMap());
private boolean redoPrimaryKeyColumns = false;
/** /**
* Constructor. Supply described type and owning repository. * Constructor. Supply described type and owning repository.
@ -418,18 +416,15 @@ public class ClassMapping
*/ */
public Column[] getPrimaryKeyColumns() { public Column[] getPrimaryKeyColumns() {
if (getIdentityType() == ID_APPLICATION && isMapped()) { if (getIdentityType() == ID_APPLICATION && isMapped()) {
if (_cols.length == 0 || redoPrimaryKeyColumns) { if (_cols.length == 0) {
FieldMapping[] pks = getPrimaryKeyFieldMappings(); FieldMapping[] pks = getPrimaryKeyFieldMappings();
Collection cols = new ArrayList(pks.length); Collection cols = new ArrayList(pks.length);
Column[] fieldCols; Column[] fieldCols;
for (int i = 0; i < pks.length; i++) { for (int i = 0; i < pks.length; i++) {
fieldCols = pks[i].getColumns(); fieldCols = pks[i].getColumns();
if (fieldCols.length == 0) { if (fieldCols.length == 0) {
// some pk columns depends on fk. At this moment, _cols = new Column[0];
// the fk may not contain complete information. return _cols;
// need to redo the primary key again later on
redoPrimaryKeyColumns = true;
continue;
} }
for (int j = 0; j < fieldCols.length; j++) for (int j = 0; j < fieldCols.length; j++)
cols.add(fieldCols[j]); cols.add(fieldCols[j]);
@ -835,8 +830,11 @@ public class ClassMapping
FieldMapping[] fms = getFieldMappings(); FieldMapping[] fms = getFieldMappings();
for (int i = 0; i < fms.length; i++) { for (int i = 0; i < fms.length; i++) {
if (fms[i].getDefiningMetaData() == this) { if (fms[i].getDefiningMetaData() == this) {
if (fms[i].getForeignKey() != null && boolean fill = getMappingRepository().getMappingDefaults().
fms[i].getStrategy() instanceof RelationFieldStrategy) { defaultMissingInfo();
ForeignKey fk = fms[i].getForeignKey();
if (fill && fk != null &&
fk.getPrimaryKeyColumns().length == 0) {
// set resolve mode to force this field mapping to be // set resolve mode to force this field mapping to be
// resolved again. The need to resolve again occurs when // resolved again. The need to resolve again occurs when
// a primary key is a relation field with the foreign key // a primary key is a relation field with the foreign key
@ -845,11 +843,10 @@ public class ClassMapping
// resolveNonRelationMapping. Since it is a relation // resolveNonRelationMapping. Since it is a relation
// field, the foreign key will be constructed. However, // field, the foreign key will be constructed. However,
// the primary key of the parent entity may not have been // 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); fms[i].setResolve(MODE_META);
if (fms[i].getStrategy() != null)
// set strategy to null to force fk to be re-constructed fms[i].getStrategy().map(false);
fms[i].setStrategy(null, false);
} }
fms[i].resolve(MODE_MAPPING); fms[i].resolve(MODE_MAPPING);
} }