Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,10 @@
}
if ( !repository && jakartaDataRepository ) {
repository = true;
sessionType = springInjection
? SPRING_STATELESS_SESSION_PROVIDER
: HIB_STATELESS_SESSION;
addDaoConstructor( null );
// Jakarta Data defaults to StatelessSession, not EntityManager
sessionType = HIB_STATELESS_SESSION;
// If it's Spring, we wrap the StatelessSession in ObjectProvider
sessionType = addDaoConstructor( null );
}
if ( needsDefaultConstructor() ) {
addDefaultConstructor();
Expand Down Expand Up @@ -895,7 +895,11 @@
* it.
*/
private String addDaoConstructor(@Nullable ExecutableElement method) {
final String sessionType = method == null ? this.sessionType : fullReturnType(method);
final String returnType = method == null ? this.sessionType : fullReturnType( method );
final String sessionType =
jakartaDataRepository && springInjection
? SPRING_OBJECT_PROVIDER + '<' + returnType + '>'
: returnType;
Comment on lines +899 to +902

Check notice

Code scanning / CodeQL

Possible confusion of local and field Note

Potentially confusing name: method
addDaoConstructor
also refers to field
sessionType
(as this.sessionType).
final String sessionVariableName = getSessionVariableName( sessionType );
final String name = method == null ? sessionVariableName : method.getSimpleName().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.processor.model.Metamodel;
import org.hibernate.processor.util.Constants;

import static org.hibernate.processor.util.Constants.HIB_STATELESS_SESSION;
import static org.hibernate.processor.util.Constants.INJECT;
import static org.hibernate.processor.util.Constants.NONNULL;

Expand Down Expand Up @@ -126,17 +127,29 @@ public String getAttributeDeclarationString() {
.append("public ");
notNull( declaration );
declaration
.append(annotationMetaEntity.importType(sessionTypeName))
.append(annotationMetaEntity.importType(providedSessionType()))
.append(" ")
.append(methodName)
.append("() {")
.append("\n\treturn ")
.append(sessionVariableName)
.append(sessionVariableName);
if ( annotationMetaEntity.isProvidedSessionAccess() ) {
declaration
.append( ".getObject()" );
}
declaration
.append(";\n}");
}
return declaration.toString();
}

private String providedSessionType() {
return annotationMetaEntity.isProvidedSessionAccess()
//TODO: assuming provided sessions are always StatelessSessions for now
? HIB_STATELESS_SESSION
: sessionTypeName;
}

/**
* In Quarkus we use the Quarkus-specific {@code @PersistenceUnit}
* CDI qualifier annotation to inject the {@code StatelessSession}
Expand Down