When using hibernate reactive with hibernate 6, I’m getting a org.hibernate.HibernateException: java.util.ConcurrentModificationException when trying to use window functions with the HibernateCriteriaBuilder. Example
final var cb = sessionFactory.getCriteriaBuilder();
final var query = cb.createQuery(Long.class);
final var root = query.from(Entity.class);
final var rowNumber = cb.rowNumber(
cb.createWindow()
.partitionBy(root.get("chargePoint"))
.orderBy(cb.desc(root.get("startTime")))
);
query.select(rowNumber.alias("rowNumber"));
session.createQuery(query).getResultList();
Expected result A query is generated that retrieves a list of the row numbers of the entities. Actual result
From quick debugging I’ve found these lines to be very suspicious: hibernate-core-6.2.1.Final-sources.jar!/org/hibernate/query/sqm/tree/expression/SqmWindow.java:174 hibernate-core-6.2.1.Final-sources.jar!/org/hibernate/query/sqm/tree/expression/SqmWindow.java:178 In this fragment from hibernate-core-6.2.1.Final-sources.jar!/org/hibernate/query/sqm/tree/expression/SqmWindow.java it looks like when copying from partitions and orderList it is added to the original lists instead of the newly created partitionsCopy and orderListCopy which causes the ConcurrentModificationException.
final List<SqmExpression<?>> partitionsCopy = new ArrayList<>( this.partitions.size() );
for ( SqmExpression<?> partition : this.partitions ) {
partitions.add( partition.copy( context ) );
}
final List<SqmSortSpecification> orderListCopy = new ArrayList<>( this.orderList.size() );
for ( SqmSortSpecification sortSpecification : this.orderList ) {
orderList.add( sortSpecification.copy( context ) );
}
|