Skip to content

Commit ed05cdf

Browse files
committed
improved explanations of constructor stuff for repositories
1 parent 17eccc3 commit ed05cdf

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,13 +936,12 @@ void addEventBus() {
936936

937937
/**
938938
* For usage with CDI, but outside Quarkus, Jakarta Data
939-
* repositories use {@code @PersistenceUnit} to obtain an
940-
* {@code EntityManagerFactory} via field injection. So in
941-
* that case we will need a {@link DefaultConstructor default
942-
* constructor}. We don't do this in Quarkus, because there
943-
* we can just inject the {@code StatelessSession} directly,
944-
* and so in Quarkus we don't need the default constructor
945-
* at all.
939+
* repositories use {@code @PersistenceUnit} to obtain
940+
* an {@code EntityManagerFactory} via field injection.
941+
* So here we need a {@linkplain DefaultConstructor
942+
* default constructor}. We don't need one in Quarkus,
943+
* because in Quarkus we can inject a container-managed
944+
* {@code StatelessSession} directly.
946945
*/
947946
boolean needsDefaultConstructor() {
948947
return jakartaDataRepository

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/DefaultConstructor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
/**
2323
* Used by the container to instantiate a Jakarta Data repository.
24+
* This is a constructor with no parameters, used to instantiate
25+
* a repository which then uses field injection to obtain its
26+
* dependencies. By contrast, a {@link RepositoryConstructor} has
27+
* a parameter which accepts the session as an argument, allowing
28+
* direct instantiation or constructor injection. This class is
29+
* only needed because {@code @PersistenceUnit} is incompatible
30+
* with CDI-style constructor injection.
2431
*
2532
* @author Gavin King
2633
*/

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/RepositoryConstructor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
import static org.hibernate.processor.util.Constants.NONNULL;
1515

1616
/**
17-
* A general purpose constructor which accepts the session.
17+
* A general purpose constructor which accepts the session as an
18+
* argument. This constructor is compatible with use via direct
19+
* instantiation or CDI-style constructor injection. By contrast,
20+
* {@link DefaultConstructor} is used to instantiate a repository
21+
* which obtains its session using field injection.
1822
*
1923
* @author Gavin King
2024
*/

0 commit comments

Comments
 (0)