{"record":{"id":"48f421f6b123791a","repo":"hibernate/hibernate-orm","slug":"cannot-instantiate-class-it-has-no-construct","errorCode":null,"errorMessage":"Cannot instantiate class '{}' (it has no constructor with signature {}, and not every argument has an alias)","messagePattern":"Cannot instantiate class '(.+?)' \\(it has no constructor with signature (.+?), and not every argument has an alias\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java","lineNumber":181,"sourceCode":"\t\t\t\t\t\t.collect( toList() ),\n\t\t\t\tcreationState.getSqlAstCreationContext()\n\t\t\t\t\t\t.getMappingMetamodel()\n\t\t\t\t\t\t.getTypeConfiguration()\n\t\t);\n\t\tif ( constructor != null ) {\n\t\t\tconstructor.setAccessible( true );\n\t\t\treturn new DynamicInstantiationAssemblerConstructorImpl<>( constructor, javaType, argumentReaders );\n\t\t}\n\n\t\tif ( LOG.isDebugEnabled() ) {\n\t\t\tLOG.debugf(\n\t\t\t\t\t\"Could not locate appropriate constructor for dynamic instantiation of [%s]; attempting bean-injection instantiation\",\n\t\t\t\t\tjavaType.getTypeName()\n\t\t\t);\n\t\t}\n\n\t\tif ( !areAllArgumentsAliased) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"Cannot instantiate class '\" + javaType.getTypeName() + \"'\"\n\t\t\t\t\t\t\t+ \" (it has no constructor with signature \" + signature()\n\t\t\t\t\t\t\t+ \", and not every argument has an alias)\"\n\t\t\t);\n\t\t}\n\t\tif ( !duplicatedAliases.isEmpty() ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"Cannot instantiate class '\" + javaType.getTypeName() + \"'\"\n\t\t\t\t\t\t\t+ \" (it has no constructor with signature \" + signature()\n\t\t\t\t\t\t\t+ \", and has arguments with duplicate aliases [\"\n\t\t\t\t\t\t\t+ StringHelper.join( \",\", duplicatedAliases) + \"])\"\n\t\t\t);\n\t\t}\n\n\t\treturn new DynamicInstantiationAssemblerInjectionImpl<>( javaType, argumentReaders );\n\t}\n\n\tprivate static Class<?> argumentClass(ArgumentReader<?> reader) {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/results/graph/instantiation/internal/DynamicInstantiationResultImpl.java#L163-L199","documentation":"Thrown for HQL dynamic class instantiation (`select new com.acme.Dto(...)`) when Hibernate cannot find a constructor of the target class whose parameter types match the selected arguments in order, and the only remaining strategy - alias-based bean injection into fields/setters - is unavailable because at least one argument has no alias. The message includes the signature Hibernate was looking for, derived from the resolved argument types.","triggerScenarios":"`select new org.acme.PersonDto(e.id, e.name)` where PersonDto has no `(Long, String)` constructor and arguments are unaliased; entity attribute type changed (e.g. Date to LocalDate) so the previously matching DTO constructor no longer matches; selecting more arguments than any constructor accepts.","commonSituations":"DTO signature drift after entity refactors; adding a column to the select list without updating the DTO; primitive-vs-wrapper or java.util.Date-vs-temporal type mismatches between the selection and the constructor; upgrading Hibernate versions where argument type resolution changed subtly.","solutions":["Add a constructor to the target class whose parameter types exactly match the selected expressions (order and types), e.g. `public PersonDto(Long id, String name)`","Alternatively alias every argument (`e.id as id`) and expose settable fields or setters with matching names so the injection fallback can be used","Verify the actual argument types by temporarily querying `Object[]` (`select e.id, e.name ...` with `Object[].class`) and compare against the constructor you provide"],"exampleFix":"// before\nselect new org.acme.PersonDto(e.id, e.name) from Person e   // PersonDto has no (Long,String) ctor\n// after\npublic PersonDto(Long id, String name) { ... }   // matches the selection order and types","handlingStrategy":"validation","validationCode":"// Discover the exact argument types Hibernate will resolve, then mirror them in the DTO constructor\nList<Object[]> probe = session.createQuery(\"select e.id, e.name from Employee e\", Object[].class).setMaxResults(1).getResultList();\nif (!probe.isEmpty()) {\n    for (Object v : probe.get(0)) System.out.println(v == null ? \"null\" : v.getClass().getName());\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalStateException e) { if (e.getMessage().contains(\"no constructor with signature\")) { /* fix DTO ctor per the printed signature */ } throw e; }","preventionTips":["Keep one constructor on the DTO that mirrors the projection 1:1 (order + types) and regenerate both together","After changing an entity attribute type, grep for DTO projections of that attribute and update constructors","Use boxed types (Long/Integer/BigDecimal) matching Hibernate's resolution, especially Long for ids and counts"],"tags":["hql","dynamic-instantiation","dto","constructor","select-new","bean-injection"],"backgroundTag":"hql-dynamic-instantiation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}