Skip to content

Commit b0f62b1

Browse files
committed
mention Spring-specific stuff in Hibernate Data Repositories doc
1 parent 7b73bf0 commit b0f62b1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ This usually happens via dependency injection, so you'll need to make sure that
103103
- in a Jakarta EE environment, `HibernateProcessor` generates special code which takes care of creating and destroying the `StatelessSession`, but
104104
- in other environments, this is something we need to take care of ourselves.
105105

106+
Note that a `StatelessSession` should never be shared across transactions.
107+
106108
[CAUTION]
107109
====
108110
Depending on the libraries in your build path, `HibernateProcessor` generates different code.
109111
For example, if Quarkus is on the build path, the repository implementation is generated to obtain the `StatelessSession` directly from CDI in a way which works in Quarkus but not in WildFly.
112+
Similarly, if Spring is in the build path, the repository implementation is generated to use `ObjectProvider<StatelessSession>`, since Spring is not capable of transparently proxying contextual objects like CDI does.
110113
====
111114

112115
If you have multiple persistence units, you'll need to disambiguate the persistence unit for a repository interface using `@Repository(dataStore="my-persistence-unit-name")`.
@@ -120,7 +123,16 @@ In principle, any implementation of `jakarta.inject` may be used to inject a rep
120123
@Inject Library library;
121124
----
122125

123-
However, this code will fail if the repository implementation is not able to obtain a `StatelessSession` from the bean container.
126+
Of course, this code will fail if the repository implementation is not able to obtain a `StatelessSession` from the bean container.
127+
128+
[NOTE]
129+
====
130+
Unfortunately, `jakarta.inject` on its own is rather incomplete, and does not specify how injectable beans should be discovered.
131+
Therefore, `HibernateProcessor` adds an appropriate bean-defining annotation to the repository implementation class, either:
132+
133+
- `@Dependent` if CDI is available, or
134+
- `@Component` if Spring is available.
135+
====
124136

125137
It's always possible to instantiate a repository implementation directly.
126138

0 commit comments

Comments
 (0)