simplify code examples by using conveniences of HibernatePersistenceConfiguration
This commit is contained in:
parent
438b9bdc85
commit
030e1fdc25
|
@ -239,8 +239,14 @@ SessionFactory sessionFactory =
|
||||||
new HibernatePersistenceConfiguration("Bookshop")
|
new HibernatePersistenceConfiguration("Bookshop")
|
||||||
.managedClass(Book.class)
|
.managedClass(Book.class)
|
||||||
.managedClass(Author.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
|
// Create a new SessionFactory
|
||||||
.createEntityManagerFactory();
|
.createEntityManagerFactory();
|
||||||
----
|
----
|
||||||
|
|
|
@ -272,8 +272,6 @@ package org.hibernate.example;
|
||||||
import org.hibernate.jpa.HibernatePersistenceConfiguration;
|
import org.hibernate.jpa.HibernatePersistenceConfiguration;
|
||||||
|
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
import static jakarta.persistence.PersistenceConfiguration.*;
|
|
||||||
import static org.hibernate.cfg.JdbcSettings.*;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -281,15 +279,12 @@ public class Main {
|
||||||
new HibernatePersistenceConfiguration("Bookshelf")
|
new HibernatePersistenceConfiguration("Bookshelf")
|
||||||
.managedClass(Book.class)
|
.managedClass(Book.class)
|
||||||
// use H2 in-memory database
|
// use H2 in-memory database
|
||||||
.property(JDBC_URL, "jdbc:h2:mem:db1")
|
.jdbcUrl("jdbc:h2:mem:db1")
|
||||||
.property(JDBC_USER, "sa")
|
.jdbcCredentials("sa", "")
|
||||||
.property(JDBC_PASSWORD, "")
|
|
||||||
// use Agroal connection pool
|
// use Agroal connection pool
|
||||||
.property("hibernate.agroal.maxSize", 20)
|
.property("hibernate.agroal.maxSize", 20)
|
||||||
// display SQL in console
|
// display SQL in console
|
||||||
.property(SHOW_SQL, true)
|
.showSql(true, true, true)
|
||||||
.property(FORMAT_SQL, true)
|
|
||||||
.property(HIGHLIGHT_SQL, true)
|
|
||||||
.createEntityManagerFactory();
|
.createEntityManagerFactory();
|
||||||
|
|
||||||
// export the inferred database schema
|
// export the inferred database schema
|
||||||
|
|
Loading…
Reference in New Issue