I migrate Spring Boot 2 to version 3. I use Hibernate 6.3.1 Final, Java 17.
After migration, my criteria queries throw InvalidDataAccessResourceUsageException.
@Entity
public class FooEntity {
@Id
private Long id;
@Column
@Lob
private String comment;
...
}
public List<FooEntity> search(FooFilters filters) {
Specification<FooEntity> specification = getSpecification(filters);
return fooRepository.findAll(specification);
}
private Specification<FooEntity> getSpecification(FooFilters filters) {
return (root, query, criteriaBuilder) -> {
List<Predicate> p = new ArrayList<>();
if (StringUtils.isNotBlank(filters.comment())) {
p.add(criteriaBuilder.like(
criteriaBuilder.lower(root.get(FooEntity_.COMMENT)),
"%" + filters.comment() + "%"));
}
return criteriaBuilder.and(p.toArray(Predicate[]::new));
};
}
Foo is entity with comment field which is String annotated as @Lob. Tests are run on h2 database. I rerun test without @Lob annotation and it works fine.
I receive exception:
jakarta.servlet.ServletException: Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: Parameter 1 of function 'lower()' has type 'STRING', but argument is of type 'java.lang.String'
Whole example: https://github.com/dcwik96/SpringBoot3LobException
root.get(FooEntity_.COMMENT)is returning a "BASIC" type which is backed to STRING in hibernate from what I've seen with your example.A quickfix would be to add specific cast to
java.lang.Stringlike this :root.get(FooEntity_.COMMENT).as(String.class)By doing so, you're code runs without a problem.
Maybe their is a better solution but this one is working. Maybe some information about
@Lobchanges in Hibernate's CHANGELOG can be found between your previous version (in SB2) and the new one (which is the latest in SB3).