code: private List<ForeignKey> getForeignKeys(Entity entity) {
          List<ForeignKey> result = newArrayList();
  
          // get all tables involved in this entity fk.
          List<Table> involvedTables = newArrayList(); // use list to preserve fk ordering.
          for (Attribute a : entity.getCurrentAttributes()) {
              if (a.isInFk()) {
                  String fkTableName = a.getColumnConfig().getTableName();
                  Assert.notNull(fkTableName);
                  Table t = topLevelCfg.getMetadata().getTableByName(fkTableName);
                  if (!involvedTables.contains(t)) {
                      involvedTables.add(t);
                  }
              }
          }
  
          // get all the imported key of the involved tables
          for (Table table : involvedTables) {
              // keep only the fk that are really bound to the passed entity
              for (ForeignKey fk : table.getForeignKeys()) {
                  if (relationExists(entity, fk)) {
                      result.add(fk);
                  }
              }
          }
  
          return result;
      }
docs: Note: the passed entity may include fields that come from different tables: Not a problem, this method supports it.