Skip to content

Commit

Permalink
simplify code examples by using conveniences of HibernatePersistenceC…
Browse files Browse the repository at this point in the history
…onfiguration
gavinking committed Nov 24, 2024
1 parent 438b9bd commit 030e1fd
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 8 additions & 2 deletions documentation/src/main/asciidoc/introduction/Configuration.adoc
Original file line number Diff line number Diff line change
@@ -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();
----
11 changes: 3 additions & 8 deletions documentation/src/main/asciidoc/introduction/Introduction.adoc
Original file line number Diff line number Diff line change
@@ -272,24 +272,19 @@ 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) {
var sessionFactory =
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

0 comments on commit 030e1fd

Please sign in to comment.