allow instantiation via non-public constructor in HQL

This commit is contained in:
Gavin 2023-05-20 11:10:01 +02:00 committed by Christian Beikov
parent 13d58901d5
commit 6941582cee
1 changed files with 7 additions and 3 deletions

View File

@ -7,7 +7,9 @@
package org.hibernate.sql.results.graph.instantiation.internal; package org.hibernate.sql.results.graph.instantiation.internal;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -116,11 +118,13 @@ public class DynamicInstantiationAssemblerInjectionImpl<T> implements DomainResu
public T assemble(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) { public T assemble(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) {
final T result; final T result;
try { try {
result = target.getJavaTypeClass().newInstance(); final Constructor<T> constructor = target.getJavaTypeClass().getDeclaredConstructor();
constructor.setAccessible( true );
result = constructor.newInstance();
} }
catch (IllegalAccessException | InstantiationException | java.lang.InstantiationException e) { catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | java.lang.InstantiationException e) {
throw new InstantiationException( "Error instantiating class '" throw new InstantiationException( "Error instantiating class '"
+ target.getJavaType().getTypeName() + "' using default constructor", e ); + target.getJavaType().getTypeName() + "' using default constructor: " + e.getMessage(), e );
} }
for ( BeanInjection beanInjection : beanInjections ) { for ( BeanInjection beanInjection : beanInjections ) {
beanInjection.getBeanInjector().inject( beanInjection.getBeanInjector().inject(