You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/repositories/Configuration.adoc
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,10 +103,13 @@ This usually happens via dependency injection, so you'll need to make sure that
103
103
- in a Jakarta EE environment, `HibernateProcessor` generates special code which takes care of creating and destroying the `StatelessSession`, but
104
104
- in other environments, this is something we need to take care of ourselves.
105
105
106
+
Note that a `StatelessSession` should never be shared across transactions.
107
+
106
108
[CAUTION]
107
109
====
108
110
Depending on the libraries in your build path, `HibernateProcessor` generates different code.
109
111
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.
110
113
====
111
114
112
115
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
120
123
@Inject Library library;
121
124
----
122
125
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
+
====
124
136
125
137
It's always possible to instantiate a repository implementation directly.
0 commit comments