System.err.println ("GETNODEBYRELATION "+rel);
    private Node getNodeByRelation (DbTxn txn, Node home, String kstr, Relation rel) throws Exception {	Node node = null;	if (rel.virtual) {	    node = new Node (home, kstr, safe, rel.prototype);		    if (rel.prototype != null) {	        node.setPrototype (rel.prototype);	        node.setDbMapping (app.getDbMapping (rel.prototype));	    } else {	        node.setDbMapping (rel.getVirtualMapping ());	    }	} else if (rel != null && rel.groupby != null) {	    node = home.getGroupbySubnode (kstr, false);	    if (node == null && (rel.otherType == null || !rel.otherType.isRelational ())) {	        node = db.getNode (txn, kstr);	        node.nmgr = safe;	    }	    return node;	} else if (rel == null || rel.otherType == null || !rel.otherType.isRelational ()) {	    node = db.getNode (txn, kstr);	    node.nmgr = safe;	    node.setDbMapping (rel.otherType);	    return node;	} else {	    System.err.println ("GETNODEBYRELATION "+rel);	    TableDataSet tds = null;	    try {	        DbMapping dbm = rel.otherType;	        tds = new TableDataSet (dbm.getConnection (), dbm.getSchema (), dbm.getKeyDef ());	        String where = rel.buildWhere (home, home.getNonVirtualParent (), kstr);	        tds.where (where);	        if (logSql)	            app.logEvent ("### getNodeByRelation: "+tds.getSelectString());	        tds.fetchRecords ();	        if (tds.size () == 0)	            return null;	        if (tds.size () > 1)	            throw new RuntimeException ("More than one value returned by query.");	        Record rec = tds.getRecord (0);	        node = new Node (rel.otherType, rec, safe);	        // Check if node is already cached with primary Key.	        if (!rel.usesPrimaryKey()) {	            Key pk = node.getKey();	            Node existing = (Node) cache.get (pk);	            if (existing != null && existing.getState() != Node.INVALID) {	                node = existing;	            }	        }	    } finally {	        if (tds != null) {	            tds.close ();	        }	    }	}	return node;    }