Fixes issue 14914: Error related to views in DAL: cannot modify a column which maps to a non key-preserved table
authorMartin Taal <martin.taal@openbravo.com>
Thu, 28 Oct 2010 15:36:33 +0200
changeset 8832 2b2594b366d7
parent 8831 6dadb8e721ce
child 8833 beedd2ff8f70
Fixes issue 14914: Error related to views in DAL: cannot modify a column which maps to a non key-preserved table
src/org/openbravo/dal/core/DalMappingGenerator.java
--- a/src/org/openbravo/dal/core/DalMappingGenerator.java	Wed Oct 27 15:37:03 2010 +0200
+++ b/src/org/openbravo/dal/core/DalMappingGenerator.java	Thu Oct 28 15:36:33 2010 +0200
@@ -191,10 +191,11 @@
     // ignoring isUpdatable for now as this is primarily used
     // for ui and not for background processes
     // if (!p.isUpdatable() || p.isInactive()) {
-    if (p.isInactive()) {
+
+    if (p.isInactive() || p.getEntity().isView()) {
       sb.append(" update=\"false\"");
     }
-    if (p.isInactive()) {
+    if (p.isInactive() || p.getEntity().isView()) {
       sb.append(" insert=\"false\"");
     }
 
@@ -220,6 +221,13 @@
       if (p.isMandatory()) {
         sb.append(" not-null=\"true\"");
       }
+
+      if (p.isInactive() || p.getEntity().isView()) {
+        sb.append(" update=\"false\"");
+      }
+      if (p.isInactive() || p.getEntity().isView()) {
+        sb.append(" insert=\"false\"");
+      }
     }
     // sb.append(" cascade=\"save-update\"");
 
@@ -254,12 +262,21 @@
         order = order.replace(order.length() - 1, order.length(), "");
         order.append("\"");
       }
-      sb.append(TAB2 + "<bag name=\"" + p.getName() + "\" cascade=\"all,delete-orphan\" " + order
-          + getAccessorAttribute() + " inverse=\"true\">" + NL);
+
+      String mutable = "";
+      String cascade = " cascade=\"all,delete-orphan\" ";
+      if (p.getEntity().isView() || p.getTargetEntity().isView()) {
+        mutable = " mutable=\"false\" ";
+        cascade = "";
+      }
+
+      sb.append(TAB2 + "<bag name=\"" + p.getName() + "\" " + cascade + order
+          + getAccessorAttribute() + mutable + " inverse=\"true\">" + NL);
       sb.append(TAB3 + "<key column=\"" + p.getReferencedProperty().getColumnName() + "\""
           + (p.getReferencedProperty().isMandatory() ? " not-null=\"true\"" : "") + "/>" + NL);
       sb.append(TAB3 + "<one-to-many entity-name=\"" + p.getTargetEntity().getName() + "\"/>" + NL);
       sb.append(TAB2 + "</bag>" + NL);
+
     }
     return sb.toString();
   }