HHH-18218 - Improved type resolving when tuple element implements SqmExpressibleAccessor

This commit is contained in:
Cedomir Igaly 2024-06-12 12:49:05 +02:00 committed by Christian Beikov
parent 9e13bd0c48
commit 4c8e72c5ec
1 changed files with 15 additions and 1 deletions

View File

@ -14,6 +14,9 @@ import org.hibernate.sql.results.spi.RowTransformer;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.List; import java.util.List;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.tree.SqmExpressibleAccessor;
/** /**
* {@link RowTransformer} instantiating an arbitrary class * {@link RowTransformer} instantiating an arbitrary class
* *
@ -28,7 +31,7 @@ public class RowTransformerConstructorImpl<T> implements RowTransformer<T> {
final List<TupleElement<?>> elements = tupleMetadata.getList(); final List<TupleElement<?>> elements = tupleMetadata.getList();
final Class<?>[] sig = new Class[elements.size()]; final Class<?>[] sig = new Class[elements.size()];
for (int i = 0; i < elements.size(); i++) { for (int i = 0; i < elements.size(); i++) {
sig[i] = elements.get(i).getJavaType(); sig[i] = resolveElementJavaType( elements.get( i ) );
} }
try { try {
constructor = type.getDeclaredConstructor( sig ); constructor = type.getDeclaredConstructor( sig );
@ -40,6 +43,17 @@ public class RowTransformerConstructorImpl<T> implements RowTransformer<T> {
} }
} }
private static Class<?> resolveElementJavaType(TupleElement<?> element) {
if ( element instanceof SqmExpressibleAccessor ) {
SqmExpressible expressible = ( (SqmExpressibleAccessor) element ).getExpressible();
if ( expressible != null ) {
return expressible.getExpressibleJavaType().getJavaTypeClass();
}
}
return element.getJavaType();
}
@Override @Override
public T transformRow(Object[] row) { public T transformRow(Object[] row) {
try { try {