Skip to content

Commit 5f7d181

Browse files
committed
Document plugging in custom components in Hibernate ORM through CDI
1 parent 5b04ff7 commit 5f7d181

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/src/main/asciidoc/hibernate-orm.adoc

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ using the `@PersistenceUnit` annotation at the class level is not supported in t
464464

465465
Note that, similarly to what we do with the configuration property, we take into account the annotated package but also all its subpackages.
466466

467-
==== CDI integration
467+
=== CDI integration
468+
469+
[[injecting-entry-points]]
470+
==== Injecting entry points
468471

469472
If you are familiar with using Hibernate ORM in Quarkus, you probably already have injected the `EntityManager` using CDI:
470473

@@ -540,6 +543,40 @@ These components can also be injected with a specific persistence unit qualifier
540543
CriteriaBuilder criteriaBuilder;
541544
----
542545

546+
[[plugging-in-converters-entity-listeners]]
547+
==== Plugging in converters and entity listeners
548+
549+
The Quarkus extension for Hibernate ORM supports injecting link:{hibernate-orm-docs-url}#basic-jpa-convert[attribute converters] and link:{hibernate-orm-docs-url}#events-jpa-callbacks[entity listeners] into Hibernate ORM.
550+
551+
Just use them as you would in vanilla Hibernate ORM (see documentation linked above), and rely on CDI features (`@Inject`, `@PostConstruct`, `@PreDestroy`, ...) in the converter/listener implementation as needed.
552+
553+
When no CDI scope is specified, the converter/listener will behave as if it was `@Dependent` and will be instantiated once per persistence unit it's used in.
554+
555+
You can force a CDI scope by annotating the converter/listener class with for example `@ApplicationScoped`.
556+
557+
In very exotic scenarios, if you need to prevent usage of CDI in a converter/listener even though it uses CDI annotations (`@Inject`, ...), annotate it with `@Vetoed`. The class will then be instantiated by Hibernate ORM through its default constructor.
558+
559+
[[plugging-in-other-custom-components]]
560+
==== Plugging in other custom components
561+
562+
The Quarkus extension for Hibernate ORM will automatically
563+
inject components annotated with `@PersistenceUnitExtension` into Hibernate Search.
564+
565+
The annotation can optionally target a specific persistence unit with `@PersistenceUnitExtension(name = "nameOfYourPU")`.
566+
567+
This feature is available for the following component types:
568+
569+
`org.hibernate.Interceptor`::
570+
See <<interceptors>>.
571+
`org.hibernate.resource.jdbc.spi.StatementInspector`::
572+
See <<statement_inspectors>>.
573+
`org.hibernate.type.format.FormatMapper`::
574+
See <<json_xml_serialization_deserialization>>.
575+
`io.quarkus.hibernate.orm.runtime.tenant.TenantResolver`::
576+
See <<multitenancy>>.
577+
`io.quarkus.hibernate.orm.runtime.tenant.TenantConnectionResolver`::
578+
See <<programmatically-resolving-tenants-connections>>.
579+
543580
[[persistence-unit-active]]
544581
=== Activate/deactivate persistence units
545582

@@ -1473,6 +1510,7 @@ quarkus.datasource.db-kind=postgresql <2>
14731510
<1> Enable discriminator multi-tenancy.
14741511
<2> xref:datasource.adoc[Configure the datasource].
14751512

1513+
[[programmatically-resolving-tenants-connections]]
14761514
=== Programmatically Resolving Tenants Connections
14771515

14781516
If you need a more dynamic configuration for the different tenants you want to support and don't want to end up with multiple entries in your configuration file,

0 commit comments

Comments
 (0)