Skip to content

Commit 02f7af5

Browse files
hacking - tmp save
1 parent 2e49efd commit 02f7af5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/AbstractJpaQuery.java

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import jakarta.persistence.TupleElement;
2424
import jakarta.persistence.TypedQuery;
2525

26+
import java.lang.reflect.InvocationTargetException;
27+
import java.util.ArrayList;
2628
import java.util.Arrays;
2729
import java.util.Collection;
2830
import java.util.HashMap;
@@ -51,6 +53,7 @@
5153
import org.springframework.jdbc.support.JdbcUtils;
5254
import org.springframework.lang.Nullable;
5355
import org.springframework.util.Assert;
56+
import org.springframework.util.ClassUtils;
5457

5558
/**
5659
* Abstract base class to implement {@link RepositoryQuery}s.
@@ -353,6 +356,24 @@ public Object convert(Object source) {
353356
}
354357
}
355358

359+
if(type.isProjecting() && !type.getReturnedType().isInterface() && !type.getInputProperties().isEmpty()) {
360+
List<Object> ctorArgs = new ArrayList<>(type.getInputProperties().size());
361+
type.getInputProperties().forEach(it -> {
362+
ctorArgs.add(tuple.get(it));
363+
});
364+
try {
365+
return type.getReturnedType().getConstructor(ctorArgs.stream().map(Object::getClass).toArray(Class<?>[]::new)).newInstance(ctorArgs.toArray());
366+
} catch (InstantiationException e) {
367+
throw new RuntimeException(e);
368+
} catch (IllegalAccessException e) {
369+
throw new RuntimeException(e);
370+
} catch (InvocationTargetException e) {
371+
throw new RuntimeException(e);
372+
} catch (NoSuchMethodException e) {
373+
throw new RuntimeException(e);
374+
}
375+
}
376+
356377
return new TupleBackedMap(tupleWrapper.apply(tuple));
357378
}
358379

0 commit comments

Comments
 (0)