简体   繁体   中英

How to use substring in criteriaQuery api (jpa 2.0)

I'm trying to do a substring query using jpa 2.0 but I dont know how to do this. Until now I have this code:

time = builder.between(
                matchesRoot.<Integer>get("startDateTime").toString().substring(8, 13),
                Integer.getInteger(DateTimeUtil.dateTimeWithoutFormat(searchCommercialsDTO.getFinalDate())),
                Integer.getInteger(DateTimeUtil.dateTimeWithoutFormat(searchCommercialsDTO.getIniDate()))
                );

But it isn't working since I cant compile it becouse of this error:

no suitable method found for between(String,Integer,Integer) method CriteriaBuilder.between(Expression,Y#1,Y#1) is not applicable (no instance(s) of type variable(s) Y#1 exist so that argument type String conforms to formal parameter type Expression) method CriteriaBuilder.between(Expression,Expression,Expression) is not applicable (no instance(s) of type variable(s) Y#2 exist so that argument type String conforms to formal parameter type Expression) where Y#1,Y#2 are type-variables: Y#1 extends Comparable declared in method between(Expression,Y#1,Y#1) Y#2 extends Comparable declared in method between(Expression,Expression,Expression

Any suggestions? Thanks!

Substring can be used via CriteriaBuilder.substring . That of course does not operate to integer, but to string.

In current approach you are calling toString method of Path . There is no connection between substring function in resulting SQL and toString method of class that is used to build query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM