# Could not resolve attribute 'aaNbo' of 'test' due to the attribute being declared in multiple subtypes

**URL:** <https://discourse.hibernate.org/t/could-not-resolve-attribute-aanbo-of-test-due-to-the-attribute-being-declared-in-multiple-subtypes/10385>\
**Category:** Hibernate ORM\
**Created:** [September 26, 2024, 10:51am UTC](https://discourse.hibernate.org/t/could-not-resolve-attribute-aanbo-of-test-due-to-the-attribute-being-declared-in-multiple-subtypes/10385 "2024-09-26T10:51:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nataliya](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nataliya](https://discourse.hibernate.org/u/nataliya)\
**Post date:** [September 26, 2024, 10:51am UTC](https://discourse.hibernate.org/t/could-not-resolve-attribute-aanbo-of-test-due-to-the-attribute-being-declared-in-multiple-subtypes/10385/1 "2024-09-26T10:51:49Z")

</div>

Hello, we’ve migrate our project from 5 to 6.6.0 final.  
We have main entity class **test** and subclasses **test$aa** and **test$bb**. In both subclasses we have field **aaNbo** annotated manyToMany to the **same other class**  
We use single\_table mapptig for **test** class.  
Before upgrade we can use hql like this:

> def hql = “”"  
> SELECT a.id  
> FROM test a  
> LEFT JOIN a.aaNbo g  
> But now we have exception:  
> “”"IllegalArgumentException, message: org.hibernate.query.PathException: Could not resolve attribute ‘aaNbo’ of ‘test’ due to the attribute being declared in multiple subtypes ‘test$aa’ and ‘test$bb’

How we can rewrite our entities or maybe rewrite hql to get correct result?  
Why in prev version of hibernate that hql worked fine? What changes inside hibernate?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [October 3, 2024, 8:15am UTC](https://discourse.hibernate.org/t/could-not-resolve-attribute-aanbo-of-test-due-to-the-attribute-being-declared-in-multiple-subtypes/10385/2 "2024-10-03T08:15:15Z")

</div>

> [@nataliya](#):
>
> Why in prev version of hibernate that hql worked fine? What changes inside hibernate?

Because in Hibernate 5 there was a lot less validation happening at runtime, leaving possible problems to happen on the database side or even after running the query. Hibernate 6 does a lot more to fail early and highlight problems with application logic before they might cause problems.

> [@nataliya](#):
>
> How we can rewrite our entities or maybe rewrite hql to get correct result?

I would suggest never using the same attribute name in two different subtypes as you _will_ run into problems like this. If you want a temporary workaround, using the `treat` operator in your HQL query to downcast `test` into the subtype you desire might work, see the [user guide](https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#hql-function-treat) for more info.

---

<div class="post-metadata">

**Author:** ![nataliya](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@nataliya](https://discourse.hibernate.org/u/nataliya)\
**Post date:** [October 3, 2024, 9:25am UTC](https://discourse.hibernate.org/t/could-not-resolve-attribute-aanbo-of-test-due-to-the-attribute-being-declared-in-multiple-subtypes/10385/3 "2024-10-03T09:25:59Z")

</div>

Thanks for Your help
