Skip to content

Commit 330736c

Browse files
committed
use new config APIs in doc
1 parent 5ff49c8 commit 330736c

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,15 @@ Alternatively, the venerable class `org.hibernate.cfg.Configuration` allows an i
211211
----
212212
SessionFactory sessionFactory =
213213
new Configuration()
214-
.addAnnotatedClass(Book.class)
215-
.addAnnotatedClass(Author.class)
214+
.addAnnotatedClasses(Book.class, Author.class)
216215
// PostgreSQL
217-
.setProperty(AvailableSettings.JAKARTA_JDBC_URL, "jdbc:postgresql://localhost/example")
216+
.setJdbcUrl("jdbc:postgresql://localhost/example")
218217
// Credentials
219-
.setProperty(AvailableSettings.JAKARTA_JDBC_USER, user)
220-
.setProperty(AvailableSettings.JAKARTA_JDBC_PASSWORD, password)
218+
.setCredentials(user, password)
221219
// Automatic schema export
222-
.setProperty(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION,
223-
Action.CREATE.getExternalJpaName())
224-
// SQL statement logging
225-
.setProperty(AvailableSettings.SHOW_SQL, TRUE.toString())
226-
.setProperty(AvailableSettings.FORMAT_SQL, TRUE.toString())
227-
.setProperty(AvailableSettings.HIGHLIGHT_SQL, TRUE.toString())
220+
.setSchemaExportAction(Action.CREATE)
221+
// SQL statement logging, formatting, highlighting
222+
.showSql(true, true, true)
228223
// Create a new SessionFactory
229224
.buildSessionFactory();
230225
----

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,23 @@ package org.hibernate.example;
299299
300300
import org.hibernate.cfg.Configuration;
301301
302-
import static java.lang.Boolean.TRUE;
303302
import static java.lang.System.out;
304-
import static org.hibernate.cfg.AvailableSettings.*;
305303
306304
public class Main {
305+
307306
public static void main(String[] args) {
308-
var sessionFactory = new Configuration()
309-
.addAnnotatedClass(Book.class)
310-
// use H2 in-memory database
311-
.setProperty(URL, "jdbc:h2:mem:db1")
312-
.setProperty(USER, "sa")
313-
.setProperty(PASS, "")
314-
// use Agroal connection pool
315-
.setProperty("hibernate.agroal.maxSize", "20")
316-
// display SQL in console
317-
.setProperty(SHOW_SQL, TRUE.toString())
318-
.setProperty(FORMAT_SQL, TRUE.toString())
319-
.setProperty(HIGHLIGHT_SQL, TRUE.toString())
320-
.buildSessionFactory();
307+
var sessionFactory =
308+
new Configuration()
309+
.addAnnotatedClass(Book.class)
310+
// use H2 in-memory database
311+
.setJdbcUrl("jdbc:h2:mem:db1")
312+
.setCredentials("sa", "")
313+
// use Agroal connection pool
314+
.setProperty("hibernate.agroal.maxSize", "20")
315+
// display, format, highlight SQL in console
316+
.showSql(true, true, true)
317+
// create the factory
318+
.buildSessionFactory();
321319
322320
// export the inferred database schema
323321
sessionFactory.getSchemaManager().exportMappedObjects(true);
@@ -417,6 +415,7 @@ import static org.hibernate.cfg.AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTIO
417415
import static org.hibernate.tool.schema.Action.CREATE;
418416
419417
public class Main {
418+
420419
public static void main(String[] args) {
421420
var factory = createEntityManagerFactory("example",
422421
// export the inferred database schema
@@ -460,6 +459,7 @@ public class Main {
460459
entityManager.close();
461460
}
462461
}
462+
463463
}
464464
----
465465

0 commit comments

Comments
 (0)