diff --git a/documentation/src/main/asciidoc/introduction/Configuration.adoc b/documentation/src/main/asciidoc/introduction/Configuration.adoc index 3be56b35a1..a8c40d5fbf 100644 --- a/documentation/src/main/asciidoc/introduction/Configuration.adoc +++ b/documentation/src/main/asciidoc/introduction/Configuration.adoc @@ -368,17 +368,24 @@ This feature is extremely useful for testing. // .Importing test or reference data ==== The easiest way to pre-initialize a database with test or "reference" data is to place a list of SQL `insert` statements in a file named, for example, `import.sql`, and specify the path to this file using the property `jakarta.persistence.schema-generation.create-script-source`. - -This approach is cleaner than writing Java code to instantiate entity instances and calling `persist()` on each of them. +We've already seen an <> of this approach, which is cleaner than writing Java code to instantiate entity instances and calling `persist()` on each of them. ==== +As we mentioned <>, it can also be useful to control schema export programmatically. + [TIP] // .Programmatic schema export ==== -Alternatively, the `SchemaManager` API allow you to control schema export programmatically. +The `SchemaManager` API allows programmatic control over schema export: [source,java] sessionFactory.getSchemaManager().exportMappedObjects(true); + +JPA has a more limited and less ergonomic API: + +[source,java] +Persistence.generateSchema("org.hibernate.example", + Map.of(JAKARTA_HBM2DDL_DATABASE_ACTION, CREATE)) ==== [[logging-generated-sql]] diff --git a/documentation/src/main/asciidoc/introduction/Introduction.adoc b/documentation/src/main/asciidoc/introduction/Introduction.adoc index 7a42b97d8b..5ceb75d900 100644 --- a/documentation/src/main/asciidoc/introduction/Introduction.adoc +++ b/documentation/src/main/asciidoc/introduction/Introduction.adoc @@ -648,6 +648,7 @@ sessionFactory.getSchemaManager().truncateMappedObjects(); After truncating tables, we might need to initialize our test data. We may specify test data in a SQL script, for example: +[[import.sql]] [source,sql] ./import.sql ----