From 6941582ceeb094217b4d07ba2d4d07d8546fcfa7 Mon Sep 17 00:00:00 2001 From: Gavin Date: Sat, 20 May 2023 11:10:01 +0200 Subject: [PATCH] allow instantiation via non-public constructor in HQL --- .../DynamicInstantiationAssemblerInjectionImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationAssemblerInjectionImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationAssemblerInjectionImpl.java index c4cdaabdab..c289576859 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationAssemblerInjectionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationAssemblerInjectionImpl.java @@ -7,7 +7,9 @@ package org.hibernate.sql.results.graph.instantiation.internal; import java.beans.PropertyDescriptor; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; @@ -116,11 +118,13 @@ public class DynamicInstantiationAssemblerInjectionImpl implements DomainResu public T assemble(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) { final T result; try { - result = target.getJavaTypeClass().newInstance(); + final Constructor 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 '" - + target.getJavaType().getTypeName() + "' using default constructor", e ); + + target.getJavaType().getTypeName() + "' using default constructor: " + e.getMessage(), e ); } for ( BeanInjection beanInjection : beanInjections ) { beanInjection.getBeanInjector().inject(