# Hibernate 6 missing discriminator in HQL query compared to 5

**URL:** <https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941>\
**Category:** Hibernate ORM\
**Created:** [July 6, 2023, 8:16pm UTC](https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941 "2023-07-06T20:16:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminka](https://avatars.discourse-cdn.com/v4/letter/n/9e8a1a/32.png) [@nminka](https://discourse.hibernate.org/u/nminka)\
**Post date:** [July 6, 2023, 8:16pm UTC](https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941/1 "2023-07-06T20:16:16Z")

</div>

It looks like the discriminator is missing in the SQL generated when using hibernate 6. Was this removed on purpose?

```auto
String query = "SELECT z.rel.fieldc from B z left join z.rel";
Query q = s.createQuery(query);
q.getResultList();

```

Hibernate 5.6.15:  
select c1\_1\_.FIELDC as col\_0\_0\_ from B b0\_ left outer join A c1\_ on b0\_.ID=c1\_.ID **and c1\_.DISCRIMINATOR=‘C’** left outer join C c1\_1\_ on c1\_.ID=c1\_1\_.ID

Hibernate 6.1.7:  
select r1\_1.FIELDC from B b1\_0 left join (A r1\_0 join C r1\_1 on r1\_0.ID=r1\_1.ID) on r1\_0.ID=b1\_0.ID

This does not seem to affect functionality, but seems to cause negative performance on large tables.

---

<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:** [July 7, 2023, 8:57am UTC](https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941/2 "2023-07-07T08:57:00Z")

</div>

I’m guessing in Hibernate 6 we’re inner joining tables `A` and `C`, restricting only entities with this association, and this might be why the discriminator condition is not needed.

Could you please share you entity mappings? Without them is hard to tell what’s going on here.

---

<div class="post-metadata">

**Author:** ![nminka](https://avatars.discourse-cdn.com/v4/letter/n/9e8a1a/32.png) [@nminka](https://discourse.hibernate.org/u/nminka)\
**Post date:** [July 7, 2023, 12:35pm UTC](https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941/3 "2023-07-07T12:35:37Z")

</div>

Currently using the XML files, B has a many to one relationship to C which is a child of A using a discriminator.

```auto
<hibernate-mapping package="test">
	<class name="A" table="A" dynamic-insert="true" dynamic-update="true" select-before-update="true" discriminator-value="A">
	<cache usage="read-write"/>
	<id name="id" column="ID">
		<generator class="increment"/>
	</id>
	<discriminator column="DISCRIMINATOR" type="string" length="30"/>
	<property name="fielda" type="string" column="FIELDA" length="100" />
</class>
</hibernate-mapping>

<hibernate-mapping package="test">
    <class dynamic-insert="true" dynamic-update="true" name="B" select-before-update="true" discriminator-value="B" table="B">
    <id name="id" column="ID" type="long">
        <generator class="increment" />
    </id>
    <property name="fieldb" type="string" column="FIELDB" length="100"/>
    <many-to-one name="rel" column="ID" class="test.C"
        property-ref="id" update="false" insert="false" not-null="false" not-found="ignore" />
</class>
</hibernate-mapping>

<hibernate-mapping>
<subclass name="test.C" extends="test.A" dynamic-insert="true" dynamic-update="true" select-before-update="true" discriminator-value="C">
    <join table="C" fetch="select">
    <key on-delete="cascade">
        <column name="ID"/>
    </key>
    <property name="fieldc" type="string" column="FIELDC" length="100"/>
    </join>
</subclass>
</hibernate-mapping>

```

---

<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:** [July 14, 2023, 12:20pm UTC](https://discourse.hibernate.org/t/hibernate-6-missing-discriminator-in-hql-query-compared-to-5/7941/4 "2023-07-14T12:20:28Z")

</div>

Please update to Hibernate 6.2.6.Final and if the problem persists, 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.
