public List<EntityHierarchyImpl> groupEntityHierarchies() {
    while (!extendsQueue.isEmpty()) {
      // set up a pass over the queue
      int numberOfMappingsProcessed = 0;
      Iterator<ExtendsQueueEntry> iterator = extendsQueue.iterator();
      while (iterator.hasNext()) {
        final ExtendsQueueEntry entry = iterator.next();
        final SubclassEntityContainer container = subEntityContainerMap.get(entry.entityItExtends);
        if (container != null) {
          // we now have this entity's super, attach it and remove entry from extends queue
          container.add(entry.subClassEntitySource);
          iterator.remove();
          numberOfMappingsProcessed++;
        }
      }

      if (numberOfMappingsProcessed == 0) {

        // todo : we could log the waiting dependencies...
        throw currentMappingDocument
            .getMappingLocalBindingContext()
            .makeMappingException("Unable to process extends dependencies in hbm files");
      }
    }

    return entityHierarchies;
  }
 public void processMappingDocument(MappingDocument mappingDocument) {
   this.currentMappingDocument = mappingDocument;
   try {
     LOG.tracef("Processing mapping document: %s ", mappingDocument.getOrigin());
     processCurrentMappingDocument();
   } finally {
     this.currentMappingDocument = null;
   }
 }
 private void processNamedQueries(EntityElement entityElement) {
   // For backward compatibility, store named queries prefixed with
   // the class name.
   String queryNamePrefix = entityElement.getEntityName();
   queryNamePrefix =
       StringHelper.isNotEmpty(queryNamePrefix)
           ? queryNamePrefix
           : currentMappingDocument
               .getMappingLocalBindingContext()
               .qualifyClassName(entityElement.getName());
   for (final JaxbQueryElement element : entityElement.getQuery()) {
     element.setName(queryNamePrefix + "." + element.getName());
     NamedQueryBindingHelper.bindNamedQuery(element, metadata);
   }
   for (final JaxbSqlQueryElement element : entityElement.getSqlQuery()) {
     element.setName(queryNamePrefix + "." + element.getName());
     NamedQueryBindingHelper.bindNamedSQLQuery(
         element, currentMappingDocument.getMappingLocalBindingContext(), metadata);
   }
 }
  private void processCurrentMappingDocument() {
    final JaxbHibernateMapping root = currentMappingDocument.getMappingRoot();
    for (final JaxbClassElement jaxbClass : root.getClazz()) {
      // we can immediately handle <class/> elements in terms of creating the hierarchy entry
      final RootEntitySourceImpl rootEntitySource =
          new RootEntitySourceImpl(currentMappingDocument, jaxbClass);
      final EntityHierarchyImpl hierarchy = new EntityHierarchyImpl(rootEntitySource);
      entityHierarchies.add(hierarchy);
      subEntityContainerMap.put(rootEntitySource.getEntityName(), rootEntitySource);
      processSubElements(jaxbClass, rootEntitySource);
    }
    List<SubEntityElement> subEntityElements =
        new ArrayList<SubEntityElement>(root.getJoinedSubclass());
    subEntityElements.addAll(root.getUnionSubclass());
    subEntityElements.addAll(root.getSubclass());

    for (final SubEntityElement element : subEntityElements) {
      processSubclassElement(element);
    }
  }
 private void processSubclassElement(SubEntityElement element) {
   // we have to see if this things super-type has been found yet, and if not add it to the
   // extends queue
   final String entityItExtends =
       currentMappingDocument
           .getMappingLocalBindingContext()
           .qualifyClassName(element.getExtends());
   final SubclassEntityContainer container = subEntityContainerMap.get(entityItExtends);
   final SubclassEntitySourceImpl subClassEntitySource =
       createSubClassEntitySource(element, (EntitySource) container);
   final String entityName = subClassEntitySource.getEntityName();
   subEntityContainerMap.put(entityName, subClassEntitySource);
   processSubElements(element, subClassEntitySource);
   if (container != null) {
     // we already have this entity's super, attach it and continue
     container.add(subClassEntitySource);
   } else {
     // we do not yet have the super and have to wait, so add it fto the extends queue
     extendsQueue.add(new ExtendsQueueEntry(subClassEntitySource, entityItExtends));
   }
 }