Skip to content

Commit 030e1fd

Browse files
committed
simplify code examples by using conveniences of HibernatePersistenceConfiguration
1 parent 438b9bd commit 030e1fd

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

documentation/src/main/asciidoc/introduction/Configuration.adoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,14 @@ SessionFactory sessionFactory =
239239
new HibernatePersistenceConfiguration("Bookshop")
240240
.managedClass(Book.class)
241241
.managedClass(Author.class)
242-
// Set properties
243-
...
242+
// PostgreSQL
243+
.jdbcUrl("jdbc:postgresql://localhost/example")
244+
// Credentials
245+
.jdbcCredentials(user, password)
246+
// Automatic schema export
247+
.schemaToolingAction(Action.SPEC_ACTION_DROP_AND_CREATE)
248+
// SQL statement logging
249+
.showSql(true, true, true)
244250
// Create a new SessionFactory
245251
.createEntityManagerFactory();
246252
----

documentation/src/main/asciidoc/introduction/Introduction.adoc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,24 +272,19 @@ package org.hibernate.example;
272272
import org.hibernate.jpa.HibernatePersistenceConfiguration;
273273
274274
import static java.lang.System.out;
275-
import static jakarta.persistence.PersistenceConfiguration.*;
276-
import static org.hibernate.cfg.JdbcSettings.*;
277275
278276
public class Main {
279277
public static void main(String[] args) {
280278
var sessionFactory =
281279
new HibernatePersistenceConfiguration("Bookshelf")
282280
.managedClass(Book.class)
283281
// use H2 in-memory database
284-
.property(JDBC_URL, "jdbc:h2:mem:db1")
285-
.property(JDBC_USER, "sa")
286-
.property(JDBC_PASSWORD, "")
282+
.jdbcUrl("jdbc:h2:mem:db1")
283+
.jdbcCredentials("sa", "")
287284
// use Agroal connection pool
288285
.property("hibernate.agroal.maxSize", 20)
289286
// display SQL in console
290-
.property(SHOW_SQL, true)
291-
.property(FORMAT_SQL, true)
292-
.property(HIGHLIGHT_SQL, true)
287+
.showSql(true, true, true)
293288
.createEntityManagerFactory();
294289
295290
// export the inferred database schema

0 commit comments

Comments
 (0)