Skip to content

Commit c6f3d94

Browse files
committed
HHH-16548 add documentation to Short Guide
1 parent 87cceaa commit c6f3d94

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ or `org.eclipse:yasson`
122122
| <<spatial,Hibernate Spatial>> | `org.hibernate.orm:hibernate-spatial`
123123
| <<envers,Envers>>, for auditing historical data | `org.hibernate.orm:hibernate-envers`
124124
| <<jfr,Hibernate JFR>>, for monitoring via Java Flight Recorder | `org.hibernate.orm:hibernate-jfr`
125+
| Hibernate Jandex integration, for <<entity-discovery,entity discovery>> | `org.hibernate.orm:hibernate-scan-jandex`
125126
|===
126127

127128
You might also add the Hibernate {enhancer}[bytecode enhancer] to your
@@ -264,6 +265,35 @@ This API is useful if you have very advanced requirements, for example, if you'r
264265
You'll find more information in the {native-bootstrap}[User Guide], and in the {boot}[package-level documentation] of `org.hibernate.boot`.
265266
****
266267

268+
[[entity-discovery]]
269+
=== Entity discovery
270+
271+
In a Jakarta EE container environment, we don't usually need to list entity and embeddable classes explicitly in `persistence.xml`.
272+
Instead, the container scans the persistence unit `jar` file and automatically discovers classes annotated `@Entity`, `@Embeddable`, or `@MappedSuperclass`.
273+
274+
`HibernatePersistenceConfiguration` offers the same functionality if the <<optional-dependencies,optional dependency>> `hibernate-scan-jandex` is available at runtime.
275+
276+
In the following code, entity classes available on the class loader which loaded `Main.class` are automatically discovered.
277+
278+
[source,java]
279+
----
280+
SessionFactory sessionFactory =
281+
// entities discovered on ClassLoader of Main.class
282+
new HibernatePersistenceConfiguration("Bookshop", Main.class)
283+
// PostgreSQL
284+
.jdbcUrl("jdbc:postgresql://localhost/example")
285+
// Credentials
286+
.jdbcCredentials(user, password)
287+
// Automatic schema export
288+
.schemaToolingAction(Action.SPEC_ACTION_DROP_AND_CREATE)
289+
// SQL statement logging
290+
.showSql(true, true, true)
291+
// Create a new SessionFactory
292+
.createEntityManagerFactory();
293+
----
294+
295+
Notice that we were able to remove the calls to `managedClass()`.
296+
267297
[[configuration-properties]]
268298
=== Configuration using Hibernate properties file
269299

0 commit comments

Comments
 (0)