1717 * @author Gavin King
1818 */
1919public class RepositoryConstructor implements MetaAttribute {
20- private final Metamodel annotationMetaEntity ;
20+ private final AnnotationMetaEntity annotationMetaEntity ;
2121 private final String constructorName ;
2222 private final String methodName ;
2323 private final String sessionTypeName ;
@@ -30,7 +30,7 @@ public class RepositoryConstructor implements MetaAttribute {
3030 private final boolean quarkusInjection ;
3131
3232 public RepositoryConstructor (
33- Metamodel annotationMetaEntity ,
33+ AnnotationMetaEntity annotationMetaEntity ,
3434 String constructorName ,
3535 String methodName ,
3636 String sessionTypeName ,
@@ -135,6 +135,11 @@ public String getAttributeDeclarationString() {
135135 return declaration .toString ();
136136 }
137137
138+ /**
139+ * In Quarkus we use the Quarkus-specific {@code @PersistenceUnit}
140+ * CDI qualifier annotation to inject the {@code StatelessSession}
141+ * directly.
142+ */
138143 private void qualifier (StringBuilder declaration ) {
139144 if ( addInjectAnnotation && quarkusInjection && dataStore != null ) {
140145 declaration
@@ -146,13 +151,23 @@ private void qualifier(StringBuilder declaration) {
146151 }
147152 }
148153
154+ /**
155+ * In Quarkus we inject the {@code StatelessSession}
156+ * directly via the constructor. But this doesn't work
157+ * in other CDI implementations, where we need to use
158+ * the JPA {@code @PersistenceUnit} annotation for
159+ * field injection of an {@code EntityManager}. In
160+ * that case, CDI will instantiate the repository via
161+ * a {@link DefaultConstructor default constructor},
162+ * so we don't need to mark this one {@code @Inject}.
163+ */
149164 private void inject (StringBuilder declaration ) {
150165 // Jakarta Data repositories are instantiated
151166 // via the default constructor, so in that
152167 // case, this one is just for testing, unless
153168 // we are in Quarkus where we can use
154169 // constructor injection
155- if ( addInjectAnnotation && (! dataRepository || quarkusInjection ) ) {
170+ if ( addInjectAnnotation && ! annotationMetaEntity . needsDefaultConstructor ( ) ) {
156171 declaration
157172 .append ('@' )
158173 .append (annotationMetaEntity .importType ("jakarta.inject.Inject" ))
0 commit comments