# DB2iDialect generates invalid SQL when calling merge on an entity

**URL:** <https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022>\
**Category:** Hibernate ORM\
**Created:** [December 10, 2025, 10:32am UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022 "2025-12-10T10:32:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GuillaumeVT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/guillaumevt/32/2283_2.png) [@GuillaumeVT](https://discourse.hibernate.org/u/GuillaumeVT)\
**Post date:** [December 10, 2025, 10:32am UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/1 "2025-12-10T10:32:02Z")

</div>

Hello,

We are using the DB2iDialect to connect to an IBMi system (jdbc:as400)

Since upgrading to Hibernate 6.6.36.Final - straight from 6.5 because we were waiting for a bug fix - we noticed that the following methods are failing and creating invalid SQL:

- EntityManager → merge
- JpaRepository → save

This happens when using composite keys (via `@EmbeddedId`) resulting in these errors:

> [SQL0584] NULL or parameter marker in VALUES not allowed.

```auto
org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement [[SQL0584] NULL or parameter marker in VALUES not allowed.] [select cua1_0.id_column1,cua1_0.id_column2,cua1_0.column3,cua1_0.column4 from some_table cua1_0 where (cua1_0.id_column1,cua1_0.id_column2) in (select v_.c0,v_.c1 from (values (?,?)) v_(c0,c1))]; SQL [select cua1_0.id_column1,cua1_0.id_column2,cua1_0.column3,cua1_0.column4 from some_table cua1_0 where (cua1_0.id_column1,cua1_0.id_column2) in (select v_.c0,v_.c1 from (values (?,?)) v_(c0,c1))]

```

Unfortunately, I cannot provide a small repo to reproduce this issue because I can only run on a physical mainframe, and the Docker images I’ve found won’t start.

Fortunately, this may be clear and simple enough to understand the cause and the moment and the reason it started to change.

To your knowledge, is there any workaround besides using update queries?

Let me know if you want me to create a bug ticket on your Jira.

---

<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:** [December 10, 2025, 12:48pm UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/2 "2025-12-10T12:48:35Z")

</div>

Please see [Db2 for i regression in 6.6.30+ (HHH-19768 / row-value IN) – SQL0216 and SQL0584 on basic loads](https://discourse.hibernate.org/t/db2-for-i-regression-in-6-6-30-hhh-19768-row-value-in-sql0216-and-sql0584-on-basic-loads/12016) where this problem was already reported.

---

<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:** [December 12, 2025, 3:18pm UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/3 "2025-12-12T15:18:27Z")

</div>

Can you please build [this PR](https://github.com/hibernate/hibernate-orm/pull/11427) and tell us if that fixes your problem?

---

<div class="post-metadata">

**Author:** ![julbob](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@julbob](https://discourse.hibernate.org/u/julbob)\
**Post date:** [January 27, 2026, 3:23pm UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/4 "2026-01-27T15:23:34Z")

</div>

Hello,

During an upgrade of Hibernate from 6.5.3.Final to 6.6.38.Final (and now try 6.6.41.Final), I found that bug on DB2.

For the moment, I found this problem on select queries which used some field of composite primary key with annotation @EmbeddedId

---

<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:** [January 27, 2026, 3:42pm UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/5 "2026-01-27T15:42:56Z")

</div>

I’m sorry, but I have no idea what you’re trying to say. The fix is included in 6.6.41.Final, so not sure why you’re trying to upgrade to an old fix version when there is a newer one available.

---

<div class="post-metadata">

**Author:** ![julbob](https://avatars.discourse-cdn.com/v4/letter/j/8491ac/32.png) [@julbob](https://discourse.hibernate.org/u/julbob)\
**Post date:** [January 28, 2026, 9:51am UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/7 "2026-01-28T09:51:20Z")

</div>

Sorry to disturb you. I used an old and deprecated dialect (DB2400Dialect). All works in 6.6.41.Final with the correct dialect (DB2iDialect).

---

<div class="post-metadata">

**Author:** ![GuillaumeVT](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/guillaumevt/32/2283_2.png) [@GuillaumeVT](https://discourse.hibernate.org/u/GuillaumeVT)\
**Post date:** [January 28, 2026, 12:09pm UTC](https://discourse.hibernate.org/t/db2idialect-generates-invalid-sql-when-calling-merge-on-an-entity/12022/8 "2026-01-28T12:09:08Z")

</div>

Hello @beikov I’m really sorry that I missed your reply. We have been using 6.6.41 since last week and our problems are resolved, thank you!
