Fixed
Details
Assignee
Gavin KingGavin KingReporter
François DambrineFrançois DambrineLabels
Components
Fix versions
Priority
Major
Details
Details
Assignee
Gavin King
Gavin KingReporter
François Dambrine
François DambrineLabels
Components
Fix versions
Priority
Created August 13, 2020 at 7:14 AM
Updated May 9, 2022 at 10:30 AM
Resolved August 27, 2020 at 9:21 AM
In our model we have an abstract entity (called abstracttaskentity in the provided snippet) with JOINED inheritance policy.
When we try to run an HQL UPDATE query that will update some attributes of this abstract entity with a set of conditions, hibernate split the query in three parts :
create a temp table
insert all matching records in this table
launch update query
This is the generic behaviour but in our case those temporary tables are not needed and have a performance cost.
This issue was discovered because of https://hibernate.atlassian.net/browse/HHH-3326#icft=HHH-3326. There are therefore related but they are not duplicated as this issue is about removing usage of temporary table when they are not needed whereas the upper is about using them correctly when they are needed.
Minimal code to reproduce
Query q = entityManager.createQuery("UPDATE abstracttaskentity e SET " + "e.locked = true " + "WHERE e.locked = false AND e.taskId = :id"); q.setParameter("id", taskToAcquire.getTaskId()); entityManager.getTransaction().commit();
Hibernate query log
Hibernate: create table #abstracttaskentity ( id varchar(255) not null ) Hibernate: insert into #abstracttaskentity select abstractta0_.id as id from abstracttaskentity abstractta0_ where abstractta0_.locked=0 and abstractta0_.id=? Hibernate: update abstracttaskentity set locked=1, where ( id ) IN ( select id from #abstracttaskentity )
I attached a test case