Skip to content

HHH-19578 Fix @Delete queries for reactive repositories #10420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
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
8 changes: 4 additions & 4 deletions tooling/metamodel-generator/hibernate-processor.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ dependencies {
api libs.byteBuddy
api libs.logging

quarkusOrmPanacheImplementation "io.quarkus:quarkus-hibernate-orm-panache:3.6.2"
quarkusHrPanacheImplementation "io.quarkus:quarkus-hibernate-reactive-panache:3.6.2"
quarkusOrmPanacheImplementation "io.quarkus:quarkus-hibernate-orm-panache:3.24.1"
quarkusHrPanacheImplementation "io.quarkus:quarkus-hibernate-reactive-panache:3.24.1"
jakartaDataImplementation "jakarta.data:jakarta.data-api:1.0.0"
jakartaDataImplementation "org.hibernate.reactive:hibernate-reactive-core:2.2.2.Final"
jakartaDataImplementation "io.quarkus:quarkus-hibernate-orm-panache:3.6.2"
jakartaDataImplementation "org.hibernate.reactive:hibernate-reactive-core:3.0.1.Final"
jakartaDataImplementation "io.quarkus:quarkus-hibernate-orm-panache:3.24.1"
}

// The source set gets a custom configuration which extends the normal test implementation config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class ReactiveTest extends CompilationTest {
@Test
@WithClasses({ Publisher.class, Author.class, Address.class, Book.class, Library.class, Library2.class })
@WithClasses({ Publisher.class, Author.class, Address.class, Book.class, Library.class, Library2.class, RepoWithPrimary.class })
public void test() {
System.out.println( getMetaModelSourceAsString( Author.class ) );
System.out.println( getMetaModelSourceAsString( Book.class ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.processor.test.data.reactive;

import io.smallrye.mutiny.Uni;
import jakarta.data.repository.Delete;
import jakarta.data.repository.Insert;
import jakarta.data.repository.Repository;
import org.hibernate.reactive.mutiny.Mutiny;

@Repository
public interface RepoWithPrimary {
Uni<Mutiny.StatelessSession> session(); //required
@Insert
Uni<Void> insert(Book book);
@Delete
Uni<Void> delete(Book book);
@Delete
Uni<Void> deleteById(String isbn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,7 @@ void createCriteriaQuery(StringBuilder declaration) {
private void createBuilder(StringBuilder declaration) {
declaration
.append("\tvar _builder = ")
.append(localSessionName());
if ( isReactive() ) {
declaration.append(".getFactory()");
}
declaration
.append(localSessionName())
.append(".getCriteriaBuilder();\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,20 +1494,42 @@ else if ( hasAnnotation( method, JD_DELETE ) ) {

private void addDeleteMethod(ExecutableElement method, @Nullable TypeMirror returnType) {
if ( returnType != null ) {
final TypeKind kind = returnType.getKind();
if ( kind != TypeKind.VOID
&& kind != TypeKind.INT
&& kind != TypeKind.LONG ) {
message(method,
"must be 'void' or return 'int' or 'long'",
Diagnostic.Kind.ERROR);
if ( isReactive()
? isLegalReactiveDeleteReturnType(returnType)
: isLegalDeleteReturnType(returnType) ) {
createCriteriaDelete(method);
}
else {
createCriteriaDelete(method);
message(method,
isReactive()
? "must be 'Uni<Void>' or 'Uni<Integer>'"
: "must be 'void' or return 'int' or 'long'",
Diagnostic.Kind.ERROR);
}
}
}

private static boolean isLegalDeleteReturnType(TypeMirror returnType) {
final TypeKind kind = returnType.getKind();
return kind == TypeKind.VOID
|| kind == TypeKind.INT
|| kind == TypeKind.LONG;
}

private static boolean isLegalReactiveDeleteReturnType(TypeMirror returnType) {
final TypeKind kind = returnType.getKind();
if ( kind == TypeKind.DECLARED ) {
final DeclaredType type = (DeclaredType) returnType;
final TypeElement typeElement = (TypeElement) type.asElement();
final Name name = typeElement.getQualifiedName();
return name.contentEquals( Void.class.getName() )
|| name.contentEquals( Integer.class.getName() );
}
else {
return false;
}
}

private void addLifecycleMethod(ExecutableElement method) {
final TypeMirror returnType = unUniIfPossible( method, method.getReturnType() );
if ( method.getParameters().size() != 1 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ void executeQuery(StringBuilder declaration, List<String> paramTypes) {
}

void tryReturn(StringBuilder declaration) {
declaration
.append("\n\ttry {\n\t\t");
if ( !isReactive() ) {
declaration
.append("\n\ttry {\n\t\t");
}
if ( !"void".equals(fullReturnType) ) {
declaration
.append("return ");
Expand All @@ -72,7 +74,7 @@ void tryReturn(StringBuilder declaration) {

@Override
String createQueryMethod() {
return isUsingEntityManager() || isReactive()
return isUsingEntityManager()
? "createQuery"
: "createMutationQuery";
}
Expand All @@ -85,6 +87,11 @@ String specificationType() {
private void execute(StringBuilder declaration) {
declaration
.append("\t\t\t.executeUpdate()");
if ( isReactive() ) {
if ( fullReturnType.endsWith("<java.lang.Void>") ) {}
declaration
.append(".replaceWithVoid()");
}
}

@Override
Expand Down