| When we try to run an HQL UPDATE query that will update a table with a set of two conditions, hibernate split the query in three parts :
- create a temp table
- insert all matching records in this table
- launch update query
This only happen with SQLServer, the main issue is that HHH-3326 Open is not yet fixed, so, when the SQLServer tempdb has a collation that is not compatible with our current db, the query just fails with a collation conflict. 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
)
|