Hello,
after migrating from Hibernate ORM 6.2.13 to 6.3.1 I noticed, that Criteria API queries involving column with AttributeConverter<List, String> stopped working.
class StringListConverter implements AttributeConverter<List<String>, String> {
@Override
public String convertToDatabaseColumn(List<String> elements) {
return elements == null || elements.isEmpty() ? null : String.join(",", elements);
}
@Override
public List<String> convertToEntityAttribute(String dbData) {
return dbData == null ? null : List.of(dbData.split(","));
}
}
@Entity
public class Employee {
@Id
private Long id;
@Convert(converter = StringListConverter.class)
private List<String> phoneNumbers;
}
JPQL query works fine with Hibernate 6.2.* and also 6.3.0, 6.3.1.
List<String> phoneNumbers = (List<String>) em
.createQuery("select emp.phoneNumbers from Employee emp where emp.id = :EMP_ID")
.setParameter("EMP_ID", 1)
.getSingleResult();
// OK - it is as expected ["0911 111 222", "0922 222 222"]
System.out.println("phoneNumbers = " + phoneNumbers);
Equivalent JPA Criteria API query worked in versions Hibernate 6.2.* but does not work in 6.3.*
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<List> q = cb.createQuery(List.class);
Root<Employee> r = q.from(Employee.class);
q.select(r.get(Employee_.phoneNumbers));
q.where(cb.equal(r.get(Employee_.id), 1);
List<String> phoneNumbers = em.createQuery(q).getSingleResult();
// WRONG - it is [["0911 111 222", "0922 222 222"]] but should be ["0911 111 222", "0922 222 222"]
System.out.println("phoneNumbers = " + phoneNumbers);
It seems that Hibernate 6.3 wraps value of type List into an additinal List, and that IMHO is wrong.