From 74b3b217ee1b1130bfaec2803c2d01cad4a067b0 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 21 Sep 2007 09:31:15 +0000 Subject: [PATCH] * Mark object references as COMPLEX_REFERENCE if the foreign key column is also mapped as primitive property. Fixes bug 555. * Get group mapping from parent DbMapping. Fixes bug 553. --- src/helma/objectmodel/db/DbMapping.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/helma/objectmodel/db/DbMapping.java b/src/helma/objectmodel/db/DbMapping.java index 7541d7b7..2f57b250 100644 --- a/src/helma/objectmodel/db/DbMapping.java +++ b/src/helma/objectmodel/db/DbMapping.java @@ -310,9 +310,16 @@ public final class DbMapping { // check if we're overwriting another relation // if so, primitive relations get precendence to references if (old != null) { - app.logEvent("*** Duplicate mapping for " + typename + "." + rel.columnName); - if (old.isPrimitive()) { + if (rel.isPrimitive() && old.isPrimitive()) { + app.logEvent("*** Duplicate mapping for " + typename + "." + rel.columnName); + } else if (rel.isReference() && old.isPrimitive()) { + // if a column is used both in a primitive and a reference mapping, + // use primitive mapping as primary one and mark reference as + // complex so it will be fetched separately d2p.put(old.columnName.toLowerCase(), old); + rel.reftype = Relation.COMPLEX_REFERENCE; + } else if (rel.isPrimitive() && old.isReference()) { + old.reftype = Relation.COMPLEX_REFERENCE; } } } @@ -738,11 +745,11 @@ public final class DbMapping { * db-mapping with the right relations to create the group-by nodes */ public synchronized DbMapping getGroupbyMapping() { - if ((subRelation == null) || (subRelation.groupby == null)) { + if ((subRelation == null) && (parentMapping != null)) { + return parentMapping.getGroupbyMapping(); + } else if (subRelation.groupby == null) { return null; - } - - if (groupbyMapping == null) { + } else if (groupbyMapping == null) { initGroupbyMapping(); }