# DynamicInstantiationResult wrong java type constructor selected

**URL:** https://discourse.hibernate.org/t/dynamicinstantiationresult-wrong-java-type-constructor-selected/8162
**Category:** Hibernate ORM
**Created:** [August 23, 2023, 10:31am UTC](https://discourse.hibernate.org/t/dynamicinstantiationresult-wrong-java-type-constructor-selected/8162 "2023-08-23T10:31:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mariana.branescu](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mariana.branescu](https://discourse.hibernate.org/u/mariana.branescu)
#### Post date: [August 23, 2023, 10:31am UTC](https://discourse.hibernate.org/t/dynamicinstantiationresult-wrong-java-type-constructor-selected/8162/1 "2023-08-23T10:31:49Z")

</div>

Hello,

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

---

<div class="post-metadata">

### Author: ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)
#### Post date: [August 28, 2023, 8:53am UTC](https://discourse.hibernate.org/t/dynamicinstantiationresult-wrong-java-type-constructor-selected/8162/2 "2023-08-28T08:53:48Z")

</div>

Sounds like you found a bug. Please create an issue in the issue tracker([https://hibernate.atlassian.net](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](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.

---

<div class="post-metadata">

### Author: ![mariana.branescu](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@mariana.branescu](https://discourse.hibernate.org/u/mariana.branescu)
#### Post date: [September 1, 2023, 10:32am UTC](https://discourse.hibernate.org/t/dynamicinstantiationresult-wrong-java-type-constructor-selected/8162/3 "2023-09-01T10:32:45Z")

</div>

Thanks, [[HHH-17155] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-17155) created
