3

I am migrating the hibernate version from 5.0.12.Final to 5.4.28.Final and I had performed some obvious straightforward deprecated changes like changing org.hibernate.Query to org.hibernate.query.Query, but encountered the following breaking change.

Example code Snippet

Query query = this.getSessionFactory().getCurrentSession().getNamedQuery("fetchPhotos");
query.setFirstResult(firstResult);
query.setMaxResults(limit);
return query.list();

Before the version migration even we set setMaxResults value as zero which was considered as no limits, but the latest hibernate changes returning Collections#emptyList immediately whenever it satisfies the condition maxResults==0. Subsequent analysis found that the change is because of hibernate ticket, also found the library level test case to assert the behavior. Though Query.setMaxResults(0) seems illogical, the latest change enforcing us to have a condition similar to below

if(limit > 0){
   query.setMaxResults(limit);
}

The real problem is we have used query.setMaxResults(limit) snippet in umpteen places in our entire code base and changing all the code occurrences seems time-consuming. Is there any workaround exist to keep the backward compatibility behavior such as setMaxResults(0) == no limits

Prasanth Rajendran
  • 4,570
  • 2
  • 42
  • 59

0 Answers0