Skip to content

Commit 4b5d3d0

Browse files
committed
HHH-18953 correctly handle Optional in reactive repos
1 parent 4e3735d commit 4b5d3d0

File tree

2 files changed

+12
-1
lines changed
  • tooling/metamodel-generator/src

2 files changed

+12
-1
lines changed

tooling/metamodel-generator/src/jakartaData/java/org/hibernate/processor/test/data/reactive/Library2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.time.LocalDate;
2525
import java.util.List;
26+
import java.util.Optional;
2627

2728
@Repository
2829
public interface Library2 {
@@ -32,6 +33,9 @@ public interface Library2 {
3233
@Find
3334
Uni<Book> book(String isbn);
3435

36+
@Find
37+
Uni<Optional<Book>> maybeBook(String isbn);
38+
3539
@Find
3640
Uni<List<Book>> books(@By("isbn") List<String> isbns);
3741

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public String getAttributeDeclarationString() {
8585

8686
private void throwIfNull(StringBuilder declaration) {
8787
if (containerType != null) {
88+
if ( isReactive() ) {
89+
declaration
90+
.append("\n\t\t\t.map(")
91+
.append(annotationMetaEntity.importType(containerType))
92+
.append("::")
93+
.append("ofNullable");
94+
}
8895
declaration
8996
.append(')');
9097
}
@@ -157,7 +164,7 @@ private void varOrReturn(StringBuilder declaration) {
157164
declaration
158165
.append("\ttry {\n\t");
159166
}
160-
if (containerType != null) {
167+
if (containerType != null && !isReactive()) {
161168
declaration
162169
.append("\treturn ")
163170
.append(annotationMetaEntity.staticImport(containerType, "ofNullable"))

0 commit comments

Comments
 (0)