Java – JPA criteriabuilder upper gives a compilation error

I am trying to use criteriabuilder for case insensitive queries, as described in Hibernate JPA criteriabuilder ignore case queries, as well as many other problems and tutorials on the network

My code is:

public Predicate toPredicate(Root<User> root,CriteriaQuery<?> query,CriteriaBuilder builder) {
    return builder.equal(builder.upper(root.get("firstName")),"test".toUpperCase());
}

But I got a compile time error:

The version of Hibernate JPA I am using is:

<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>

Does it depend on the sleep version I use? How do I place the expression < string > instead of the path < Object >?

Thank you for your help

Solution

As the compiler said, we expect the expression path to extend from expression in this case, but you have a path to solve this problem for the following reasons

return builder.equal(builder.upper(root.<String> get("firstName")),"test".toUpperCase());

Trick is to add < string > before obtaining the method. I hope it will be helpful

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>