# Discriminator is ignored during massindexing

**URL:** <https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653>\
**Category:** Hibernate Search\
**Created:** [December 5, 2023, 2:33pm UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653 "2023-12-05T14:33:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VladDrakul1986](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vladdrakul1986/32/2363_2.png) [@VladDrakul1986](https://discourse.hibernate.org/u/VladDrakul1986)\
**Post date:** [December 5, 2023, 2:33pm UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653/1 "2023-12-05T14:33:35Z")

</div>

Hi,  
as followup to [Problem using Multitenancy Discriminator with Hibernate Search - Hibernate Search - Hibernate](https://discourse.hibernate.org/t/problem-using-multitenancy-discriminator-with-hibernate-search/8296/1) i tested the Hibernate Search 7 (7.0.0 RC2), but i encounter potentially an other bug.

The massindexer ignores the given tenantId.  
E.g: i have 3 tenants “_zero_” “_dummy2_” “_test_” assuming i have 3k rows for _test_, 0 for zero, _10 for dummy2_ and i start the massindexer with the tenant zero

```auto
      SearchSession searchSession = Search.session(getEntityManager());
      searchSession.massIndexer().startAndWait();

```

When i watch the result in luke i see that the number of documents is 3001 and _\_HSEARCH\_tenantId_ has a term count of 1 and a freq for zero 3001.  
When i search now in my tentant zero and use  
`result.total().hitCount()`  
I get value for all hit in all tenants, while  
`result.hits()` is empty.

When I run the massIndexer again let’s say for tenant _“test”_. Luke say number of documents 6002 and _\_HSEARCH\_tenantId_ has a term count of 2 (_zero_ and _test_) each having freq of 3001.  
When i search now on Tenant zero the result is the same.

Conclusion: It seems that the column annotated with @TenantId is ignored while performing a massindex and is treated like a common column. My expected behaviour is that this column will be handled like in the Hibernate ORM (e.g. add a “where TenantIdColumn = ‘MyCurrentTenantId’”)

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [December 5, 2023, 3:30pm UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653/2 "2023-12-05T15:30:12Z")

</div>

Hi,

Thanks for reporting but I’m not sure this is enough for us to work on the problem; in particular I’ve learned to not to take what Luke tells us for granted, because it tends to hide some critical information (e.g. docvalues), and is sometimes too low-level (ignores some of the tricks used in Hibernate Search, or uses an incompatible default configuration).

Do you think you could provide a reproducer for this?  
There’s a template you can start with here: [hibernate-test-case-templates/search/hibernate-search-7/orm-lucene at main · hibernate/hibernate-test-case-templates · GitHub](https://github.com/hibernate/hibernate-test-case-templates/tree/main/search/hibernate-search-7/orm-lucene)

> [@VladDrakul1986](#):
>
> My expected behaviour is that this column will be handled like in the Hibernate ORM (e.g. add a “where TenantIdColumn = ‘MyCurrentTenantId’”)

That’s certainly how it’s intended to work… And how I’ve seen Hibernate Search behave in integration tests so far 😕

---

<div class="post-metadata">

**Author:** ![VladDrakul1986](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vladdrakul1986/32/2363_2.png) [@VladDrakul1986](https://discourse.hibernate.org/u/VladDrakul1986)\
**Post date:** [December 6, 2023, 3:21pm UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653/3 "2023-12-06T15:21:11Z")

</div>

Hi,

thx @yrodiere for your response and this template.  
i forked your repo and create a test which reproduce my issue.

The behaviour divergent between both test even they should create the same result.

> <https://github.com/VladDrakul1986/hibernate-test-case-templates/blob/main/search/hibernate-search-7/orm-lucene/src/test/java/org/hibernate/search/bugs/YourIT.java>

Kind regards

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [December 6, 2023, 4:19pm UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653/4 "2023-12-06T16:19:56Z")

</div>

Thanks a lot for the reproducer!

It would seem that in this specific case, Hibernate ORM didn’t apply the filter which it usually applies automatically. Whether because of misuse in Hibernate Search, or a bug/limitation in Hibernate ORM remains to be determined.

I created [[HSEARCH-5031] - Hibernate JIRA](https://hibernate.atlassian.net/browse/HSEARCH-5031), we’ll track progress there.

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [January 16, 2024, 8:01am UTC](https://discourse.hibernate.org/t/discriminator-is-ignored-during-massindexing/8653/5 "2024-01-16T08:01:21Z")

</div>

Some update: the problem was actually caused by a bug in Hibernate ORM, [HHH-17619](https://hibernate.atlassian.net/browse/HHH-17619) , which is going to be solved in Hibernate ORM 6.4.2.
