From 030e1fdc25fb27580066ab6cbb7a104ea88d52a3 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 24 Nov 2024 10:20:14 +0100 Subject: [PATCH] simplify code examples by using conveniences of HibernatePersistenceConfiguration --- .../src/main/asciidoc/introduction/Configuration.adoc | 10 ++++++++-- .../src/main/asciidoc/introduction/Introduction.adoc | 11 +++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/documentation/src/main/asciidoc/introduction/Configuration.adoc b/documentation/src/main/asciidoc/introduction/Configuration.adoc index 2f5df9845f..3479293aaf 100644 --- a/documentation/src/main/asciidoc/introduction/Configuration.adoc +++ b/documentation/src/main/asciidoc/introduction/Configuration.adoc @@ -239,8 +239,14 @@ SessionFactory sessionFactory = new HibernatePersistenceConfiguration("Bookshop") .managedClass(Book.class) .managedClass(Author.class) - // Set properties - ... + // PostgreSQL + .jdbcUrl("jdbc:postgresql://localhost/example") + // Credentials + .jdbcCredentials(user, password) + // Automatic schema export + .schemaToolingAction(Action.SPEC_ACTION_DROP_AND_CREATE) + // SQL statement logging + .showSql(true, true, true) // Create a new SessionFactory .createEntityManagerFactory(); ---- diff --git a/documentation/src/main/asciidoc/introduction/Introduction.adoc b/documentation/src/main/asciidoc/introduction/Introduction.adoc index e2c1721885..5295262ce5 100644 --- a/documentation/src/main/asciidoc/introduction/Introduction.adoc +++ b/documentation/src/main/asciidoc/introduction/Introduction.adoc @@ -272,8 +272,6 @@ package org.hibernate.example; import org.hibernate.jpa.HibernatePersistenceConfiguration; import static java.lang.System.out; -import static jakarta.persistence.PersistenceConfiguration.*; -import static org.hibernate.cfg.JdbcSettings.*; public class Main { public static void main(String[] args) { @@ -281,15 +279,12 @@ public class Main { new HibernatePersistenceConfiguration("Bookshelf") .managedClass(Book.class) // use H2 in-memory database - .property(JDBC_URL, "jdbc:h2:mem:db1") - .property(JDBC_USER, "sa") - .property(JDBC_PASSWORD, "") + .jdbcUrl("jdbc:h2:mem:db1") + .jdbcCredentials("sa", "") // use Agroal connection pool .property("hibernate.agroal.maxSize", 20) // display SQL in console - .property(SHOW_SQL, true) - .property(FORMAT_SQL, true) - .property(HIGHLIGHT_SQL, true) + .showSql(true, true, true) .createEntityManagerFactory(); // export the inferred database schema