File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -786,10 +786,10 @@ else if ( element.getKind() == ElementKind.INTERFACE
786786 }
787787 if ( !repository && jakartaDataRepository ) {
788788 repository = true ;
789- sessionType = springInjection
790- ? SPRING_STATELESS_SESSION_PROVIDER
791- : HIB_STATELESS_SESSION ;
792- addDaoConstructor ( null );
789+ // Jakarta Data defaults to StatelessSession, not EntityManager
790+ sessionType = HIB_STATELESS_SESSION ;
791+ // If it's Spring, we wrap the StatelessSession in ObjectProvider
792+ sessionType = addDaoConstructor ( null );
793793 }
794794 if ( needsDefaultConstructor () ) {
795795 addDefaultConstructor ();
@@ -895,7 +895,11 @@ private boolean isReactivePanacheType(TypeElement type) {
895895 * it.
896896 */
897897 private String addDaoConstructor (@ Nullable ExecutableElement method ) {
898- final String sessionType = method == null ? this .sessionType : fullReturnType (method );
898+ final String returnType = method == null ? this .sessionType : fullReturnType ( method );
899+ final String sessionType =
900+ jakartaDataRepository && springInjection
901+ ? SPRING_OBJECT_PROVIDER + '<' + returnType + '>'
902+ : returnType ;
899903 final String sessionVariableName = getSessionVariableName ( sessionType );
900904 final String name = method == null ? sessionVariableName : method .getSimpleName ().toString ();
901905
Original file line number Diff line number Diff line change 99import org .hibernate .processor .model .Metamodel ;
1010import org .hibernate .processor .util .Constants ;
1111
12+ import static org .hibernate .processor .util .Constants .HIB_STATELESS_SESSION ;
1213import static org .hibernate .processor .util .Constants .INJECT ;
1314import static org .hibernate .processor .util .Constants .NONNULL ;
1415
@@ -126,17 +127,29 @@ public String getAttributeDeclarationString() {
126127 .append ("public " );
127128 notNull ( declaration );
128129 declaration
129- .append (annotationMetaEntity .importType (sessionTypeName ))
130+ .append (annotationMetaEntity .importType (providedSessionType () ))
130131 .append (" " )
131132 .append (methodName )
132133 .append ("() {" )
133134 .append ("\n \t return " )
134- .append (sessionVariableName )
135+ .append (sessionVariableName );
136+ if ( annotationMetaEntity .isProvidedSessionAccess () ) {
137+ declaration
138+ .append ( ".getObject()" );
139+ }
140+ declaration
135141 .append (";\n }" );
136142 }
137143 return declaration .toString ();
138144 }
139145
146+ private String providedSessionType () {
147+ return annotationMetaEntity .isProvidedSessionAccess ()
148+ //TODO: assuming provided sessions are always StatelessSessions for now
149+ ? HIB_STATELESS_SESSION
150+ : sessionTypeName ;
151+ }
152+
140153 /**
141154 * In Quarkus we use the Quarkus-specific {@code @PersistenceUnit}
142155 * CDI qualifier annotation to inject the {@code StatelessSession}
You can’t perform that action at this time.
0 commit comments