hibernate buildMappings方法有什么用

时间:2018-12-13 15:37:50

标签: hibernate

org.hibernate.cfg.Configuration类中的buildMappings方法有什么用?该方法返回void。

它有什么作用?我经历了hibernate-core-3.6.9.Final.jar,代码如下。(请参阅代码部分)

该代码段摘自hibernate-core-3.6.9.Final.jar:

 public void buildMappings()
  {
    secondPassCompile();
  }


  protected void secondPassCompile()
    throws MappingException
  {
    log.trace("Starting secondPassCompile() processing");
    if (!this.isDefaultProcessed)
    {
      Object isDelimited = this.reflectionManager.getDefaults().get("delimited-identifier");
      if ((isDelimited != null) && (isDelimited == Boolean.TRUE)) {
        getProperties().put("hibernate.globally_quoted_identifiers", "true");
      }
      AnnotationBinder.bindDefaults(createMappings());
      this.isDefaultProcessed = true;
    }
    this.metadataSourceQueue.syncAnnotatedClasses();
    this.metadataSourceQueue.processMetadata(determineMetadataSourcePrecedence());
    for (CacheHolder holder : this.caches) {
      if (holder.isClass) {
        applyCacheConcurrencyStrategy(holder);
      } else {
        applyCollectionCacheConcurrencyStrategy(holder);
      }
    }
    this.caches.clear();
    try
    {
      this.inSecondPass = true;
      processSecondPassesOfType(PkDrivenByDefaultMapsIdSecondPass.class);
      processSecondPassesOfType(SetSimpleValueTypeSecondPass.class);
      processSecondPassesOfType(CopyIdentifierComponentSecondPass.class);
      processFkSecondPassInOrder();
      processSecondPassesOfType(CreateKeySecondPass.class);
      processSecondPassesOfType(SecondaryTableSecondPass.class);

      originalSecondPassCompile();

      this.inSecondPass = false;
    }
    catch (RecoverableException e)
    {
      throw ((RuntimeException)e.getCause());
    }
    for (Map.Entry<Table, List<UniqueConstraintHolder>> tableListEntry : this.uniqueConstraintHoldersByTable.entrySet())
    {
      table = (Table)tableListEntry.getKey();
      List<UniqueConstraintHolder> uniqueConstraints = (List)tableListEntry.getValue();
      uniqueIndexPerTable = 0;
      for (UniqueConstraintHolder holder : uniqueConstraints)
      {
        uniqueIndexPerTable++;
        String keyName = StringHelper.isEmpty(holder.getName()) ? "key" + uniqueIndexPerTable : holder.getName();

        buildUniqueKeyFromColumnNames(table, keyName, holder.getColumns());
      }
    }
    Table table;
    int uniqueIndexPerTable;
    applyConstraintsToDDL();
  }

我了解它对主键,唯一约束进行了一些处理..但是在什么hbm文件上却可以做到这一点。

该处理和buildMappings方法的确切用途是什么?

0 个答案:

没有答案
相关问题