DynamicInstantiationResult wrong java type constructor selected


Migrating from 5.6.4 to 6.2.6 I encountered a wrong java type constructor instantiation:
Caused by: org.hibernate.query.sqm.sql.internal.InstantiationException: Error performing dynamic instantiation : mypackage.OptionDto

OptionDto has the following constructors:

public OptionDto(long value, String title) {


public OptionDto(int value, String title) {


Extracted argument types are Long and String, but hibernate uses the constructor with type int and String.
While debuging, I noticed it evaluates that int and long are assignment compatible (see org.hibernate.query.sqm.tree.expression.Compatibility.isIntegralTypePrimitive(Class potentialIntegral)) so it selects the wrong constructor that later fails using java reflection instantiation

Sounds like you found a bug. Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

Thanks, [HHH-17155] - Hibernate JIRA created