diff --git a/org.adempiere.base/src/org/compiere/model/MColumn.java b/org.adempiere.base/src/org/compiere/model/MColumn.java index 7378f5a9bb..32e7afa03b 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MColumn.java @@ -31,6 +31,7 @@ import java.util.Locale; import java.util.Properties; import java.util.logging.Level; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.DBException; import org.compiere.db.AdempiereDatabase; import org.compiere.db.Database; @@ -54,7 +55,7 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport /** * */ - private static final long serialVersionUID = -1841918268550762201L; + private static final long serialVersionUID = 4379933682905553553L; /** * Get MColumn from Cache (immutable) @@ -128,6 +129,20 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport return table.getColumn(columnName); } // get + /** + * Get MColumn given TableName and ColumnName + * @param ctx context + * @param TableName + * @param ColumnName + * @param TrxName + * @return MColumn + */ + public static MColumn get (Properties ctx, String tableName, String columnName, String trxName) + { + MTable table = MTable.get(ctx, tableName, trxName); + return table.getColumn(columnName); + } // get + public static String getColumnName (Properties ctx, int AD_Column_ID) { return getColumnName (ctx, AD_Column_ID, null); @@ -795,8 +810,13 @@ public class MColumn extends X_AD_Column implements ImmutablePOSupport int cnt = DB.getSQLValueEx(get_TrxName(), "SELECT COUNT(*) FROM AD_Ref_Table WHERE AD_Reference_ID=?", getAD_Reference_Value_ID()); if (cnt == 1) { MRefTable rt = MRefTable.get(getCtx(), getAD_Reference_Value_ID(), get_TrxName()); - if (rt != null) - foreignTable = rt.getAD_Table().getTableName(); + if (rt != null) { + MTable table = MTable.get(getCtx(), rt.getAD_Table_ID(), get_TrxName()); + if (table == null) { + throw new AdempiereException("Table " + rt.getAD_Table_ID() + " not found"); + } + foreignTable = table.getTableName(); + } } } } else if (DisplayType.Button == refid) { diff --git a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java index 585036fe23..5f2533b4ce 100644 --- a/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java +++ b/org.adempiere.pipo.handlers/src/org/adempiere/pipo2/handler/ColumnElementHandler.java @@ -26,6 +26,7 @@ import java.util.logging.Level; import javax.xml.transform.sax.TransformerHandler; +import org.adempiere.exceptions.AdempiereException; import org.adempiere.pipo2.AbstractElementHandler; import org.adempiere.pipo2.Element; import org.adempiere.pipo2.PIPOContext; @@ -182,9 +183,14 @@ public class ColumnElementHandler extends AbstractElementHandler { } private void deferFK(Element element, MColumn mColumn) { - String foreignTable = mColumn.getReferenceTableName(); - if (foreignTable != null && ! "AD_Ref_List".equals(foreignTable)) + try { + String foreignTable = mColumn.getReferenceTableName(); + if (foreignTable != null && ! "AD_Ref_List".equals(foreignTable)) + element.deferFKColumnID = mColumn.getAD_Column_ID(); + } catch (AdempiereException e) { + // AdempiereException thrown in mColumn.getReferenceTableName() when the table is not created yet element.deferFKColumnID = mColumn.getAD_Column_ID(); + } } private void syncColumn(PIPOContext ctx, MColumn mColumn, String action, diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java index 5424e388b9..614441998f 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java @@ -186,11 +186,11 @@ public class PoFiller{ } } if (po.get_ColumnIndex(columnName) >= 0) { - MColumn col = MColumn.get(ctx.ctx, po.get_TableName(), columnName); + MColumn col = MColumn.get(ctx.ctx, po.get_TableName(), columnName, po.get_TrxName()); MTable foreignTable = null; String refTableName = col.getReferenceTableName(); if (refTableName != null) { - foreignTable = MTable.get(Env.getCtx(), refTableName); + foreignTable = MTable.get(Env.getCtx(), refTableName, po.get_TrxName()); } else { if ("Record_ID".equalsIgnoreCase(columnName)) { // special case - get the foreign table using AD_Table_ID @@ -207,7 +207,7 @@ public class PoFiller{ } } if (tableID > 0) { - foreignTable = MTable.get(Env.getCtx(), tableID); + foreignTable = MTable.get(Env.getCtx(), tableID, po.get_TrxName()); refTableName = foreignTable.getTableName(); } }