Upgrade to Hibernate 6, insert performance with Embedded IDs

Hi, new to the forum so pls let me know if the format/question makes sense.
I’m working on a spring boot application that runs a relatively small H2 database underneath. The application interacts with the DB through JPA Since moving to Spring boot 3 (from 2.7) and upgrading hibernate the insert performance (save method in a JPA repo) slowed down dramatically. Well, JPA save is not really an insert but…
After a bit of investigation the entities inserted - that use @EmbeddedId - run a select before the insert, as expected (usual check for merge). The problem is - the select generated looks like:

select p1_0.x,p1_0.y from mytable p1_0 where (p1_0.x,p1_0.y) in((‘mypieceofId1’, 1677042000000))

H2 does not pick up the index, and runs a table scan. It would work if it was

select p1_0.x,p1_0.y from mytable p1_0 where p1_0.x = ‘mypieceofId1’ and p1_0.y= 1677042000000

I would appreciate if somebody could shed some light on this behavior, if it’s a recent change and most of all if there is a way to get hibernate to generate a more efficient query.
For certain entities I can simply make them @Persistable and override isNew but for others it would require a good amount of work.
Any help/advice wcome!

Rolled back to hibernate 5, and the query is of the type

select p1_0.x,p1_0.y from mytable p1_0 where p1_0.x = ‘mypieceofId1’ and p1_0.y= 1677042000000

(that explains why it was working fine before).

You can create an improvement request for this, but we need confirmation on this matter by the H2 developers. This seems like a H2 optimizer issue to me and should IMO be fixed by H2. Which H2 version are you using?

@beikov latest released ( 2.1.214) pinged H2 community as well, it’s fixed on their latest master branch, but not released yet. I guess unless other DBs have the same problem it’s probably fine to park the issue, once H2 releases people can upgrade, or build from source.

Thanks for confirming. I’d say this is not something that Hibernate should fix, but H2. You’ll have to update once the fix is available.