Interface SchemaManager

All Superinterfaces:
SchemaManager

@Incubating public interface SchemaManager extends SchemaManager
Allows programmatic schema export, schema validation, data cleanup, data population, and schema cleanup as a convenience for writing tests.
Since:
6.2
See Also:
API Note:
This interface was added to JPA 3.2 as SchemaManager, which it now inherits, with a minor change to the naming of its operations. It is retained for backward compatibility and as a place to define additional operations like populate(), resynchronizeGenerators(), and forSchema(String).
  • Method Details

    • truncate

      void truncate()
      Truncate the database tables mapped by Hibernate entities, reset all associated sequences and tables backing table generators, and then reimport initial data from /import.sql and any other configured load script.

      Programmatic way to run SchemaTruncator.

      This operation does not affect the second-level cache. Therefore, after calling truncateMappedObjects(), it might be necessary to also call Cache.evictAllRegions() to clean up data held in the second-level cache.

      Specified by:
      truncate in interface SchemaManager
      Since:
      7.0
    • truncateTable

      @Incubating void truncateTable(String tableName)
      Truncate the given database table, and reset any associated sequence or table backing a table generator. Do not repopulate the table.

      This operation does not affect the second-level cache. Therefore, after calling truncate(), it might be necessary to also call Cache.evictRegion(String) to clean up data held in the second-level cache.

      Parameters:
      tableName - The name of the table to truncate, which must be a table mapped by some entity class or collection
      Since:
      7.2
    • populate

      void populate()
      Populate the database by executing /import.sql and any other configured load script.

      This operation does not automatically resynchronize sequences or tables backing table generators, and so it might be necessary to call resynchronizeGenerators() after calling this method.

      Programmatic way to run SchemaPopulator.

      Specified by:
      populate in interface SchemaManager
      Since:
      7.0
      See Also:
    • resynchronizeGenerators

      @Incubating void resynchronizeGenerators()
      Resynchronize sequences and table-based generators after importing entity data.

      When data is imported to the database without the use of a Hibernate session, a database sequence might become stale with respect to the data in the table for which it is used to generate unique keys. This operation restarts every sequence so that the next generated unique key will be larger than the largest key currently in use. A similar phenomenon might occur for the database table backing a table-based generator, and so this operation also updates such tables.

      Programmatic way to run GeneratorSynchronizer.

      Since:
      7.2
    • forSchema

      @Incubating SchemaManager forSchema(String schemaName)
      Obtain an instance which targets the given schema.

      This is especially useful when using multiple schemas, for example, in schema-based multitenancy.

      Parameters:
      schemaName - The name of the schema to target
      Since:
      7.1
    • forCatalog

      @Incubating SchemaManager forCatalog(String catalogName)
      Obtain an instance which targets the given catalog.
      Parameters:
      catalogName - The name of the catalog to target
      Since:
      7.1
    • exportMappedObjects

      @Deprecated(forRemoval=true, since="8.0") void exportMappedObjects(boolean createSchemas)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Export database objects mapped by Hibernate entities, and then import initial data from /import.sql and any other configured load script.

      Programmatic way to run SchemaCreator.

      Parameters:
      createSchemas - if true, attempt to create schemas, otherwise, assume the schemas already exist
      API Note:
      This operation is a synonym for SchemaManager.create(boolean).
    • dropMappedObjects

      @Deprecated(forRemoval=true, since="8.0") void dropMappedObjects(boolean dropSchemas)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Drop database objects mapped by Hibernate entities, undoing the previous export.

      Programmatic way to run SchemaDropper.

      Parameters:
      dropSchemas - if true, drop schemas, otherwise, leave them be
      API Note:
      This operation is a synonym for SchemaManager.drop(boolean).
    • validateMappedObjects

      @Deprecated(forRemoval=true, since="8.0") void validateMappedObjects()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Validate that the database objects mapped by Hibernate entities have the expected definitions.

      Programmatic way to run SchemaValidator.

      API Note:
      This operation is a synonym for SchemaManager.validate().
    • truncateMappedObjects

      @Deprecated(forRemoval=true, since="8.0") void truncateMappedObjects()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use truncate() instead.
      Truncate the database tables mapped by Hibernate entities, reset all associated sequences and tables backing table generators, and then reimport initial data from /import.sql and any other configured load script.

      Programmatic way to run SchemaTruncator.

      This operation does not affect the second-level cache. Therefore, after calling truncateMappedObjects(), it might be necessary to also call Cache.evictAllRegions() to clean up data held in the second-level cache.

      API Note:
      This operation is a synonym for truncate().