# Update query with multitenancy generating invalid SQL

**URL:** <https://discourse.hibernate.org/t/update-query-with-multitenancy-generating-invalid-sql/11292>\
**Category:** Hibernate ORM\
**Created:** [March 27, 2025, 10:08am UTC](https://discourse.hibernate.org/t/update-query-with-multitenancy-generating-invalid-sql/11292 "2025-03-27T10:08:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klompara](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/klompara/32/3735_2.png) [@Klompara](https://discourse.hibernate.org/u/Klompara)\
**Post date:** [March 27, 2025, 10:08am UTC](https://discourse.hibernate.org/t/update-query-with-multitenancy-generating-invalid-sql/11292/1 "2025-03-27T10:08:45Z")

</div>

Hello,

I am using the CurrentTenantIdentifierResolver to achieve multitenancy. My Entities/Tables have a @TenantId field/column.  
In a JPA repository I would like to set a status of multiple Entites to true/false.  
The repository function is the following:

```auto
    @Modifying
    @Query("UPDATE TriggerDAO t SET t.enabled = :status WHERE t.triggerId IN :triggerIds")
    void updateTriggerStatus(boolean status, List<UUID> triggerIds);

```

When executing the update, the following SQL is printed:

```auto
update Triggers set enabled=? where triggerId in (?) and td1_0.fkTenantId = ?

```

The tenant id is automatically appended, however the table alias td1\_0 is not set and therefore results in an error:

```auto
INVALID_ARGUMENT: Unrecognized name: td1_0 [at 1:62]
...set enabled=@p1 where triggerId in (@p2) and td1_0.fkTenantId = @p3

```

Using dependency:

```auto
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.6.11.Final</version>
        </dependency>

```

My work around would be to use a native query (but then I have to set the tenant id manually). Is there an option to keep using HQL?

---

<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:** [March 27, 2025, 10:21am UTC](https://discourse.hibernate.org/t/update-query-with-multitenancy-generating-invalid-sql/11292/2 "2025-03-27T10:21:34Z")

</div>

Please try to create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and if you are able to reproduce the issue, create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.
