Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

BETWEEN (2): [IsBetween, Between] is not supported for Redis query derivation

$
0
0

I'm a beginner at spring data redis and I'm currently using Redis database as part of my application. And I am trying to query for records between two dates.

Here is my Repository class.

public interface TransactionStatsRepository extends CrudRepository<TransactionStats, String> {    List<TransactionStats> findByCreatedAtBetween(Date startDate, Date endDate);}

I've indexed the createdAt field in my Entity class.

@RedisHash("TRANSACTION")public class TransactionStats implements Serializable {    @Id    private String id;    @Indexed    private String status;    @Indexed    private Date createdAt;//Getters and Setters

The data insertion is being done in a typical CrudRepository way using the save() method.

    public void addNewTransaction(String status, String createdAt) throws ParseException {        TransactionStats stats = new TransactionStats();        stats.setStatus(status);        stats.setCreatedAt(getStringToDate(createdAt));        transactionStatsRepository.save(stats);    }    private Date getStringToDate(String dateString) throws ParseException {        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        formatter.setTimeZone(TimeZone.getTimeZone("GMT"+ timeZoneOffset));        return formatter.parse(dateString);    }

Here is the service class method accessing the repo method

public List<TransactionStatsDTO> getForDuration(String startDuration, String endDuration) throws ParseException {        Date startDate = getStringToDate(startDuration);        Date endDate = getStringToDate(endDuration);        List<TransactionStatsDTO> transactionStatsDTOs = new ArrayList<>();        transactionStatsRepository.findByCreatedAtBetween(startDate, endDate)                .forEach(transactionStats -> transactionStatsDTOs.add(mapper.map(transactionStats, TransactionStatsDTO.class)));        return transactionStatsDTOs;    }

But the repo method findByCreatedAtBetweenwhen accessed is throwing the following exception.

Caused by: java.lang.IllegalArgumentException: BETWEEN (2): [IsBetween, Between] is not supported for Redis query derivation!    at org.springframework.data.redis.repository.query.RedisQueryCreator.from(RedisQueryCreator.java:73) ~[spring-data-redis-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:53) ~[spring-data-redis-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.redis.repository.query.RedisQueryCreator.create(RedisQueryCreator.java:41) ~[spring-data-redis-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119) ~[spring-data-commons-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.createQuery(KeyValuePartTreeQuery.java:212) ~[spring-data-keyvalue-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.prepareQuery(KeyValuePartTreeQuery.java:149) ~[spring-data-keyvalue-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.execute(KeyValuePartTreeQuery.java:107) ~[spring-data-keyvalue-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:618) ~[spring-data-commons-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.2.6.RELEASE.jar:2.2.6.RELEASE]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at com.sun.proxy.$Proxy122.findByCreatedAtBetween(Unknown Source) ~[na:na]    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]    at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.5.RELEASE.jar:5.2.5.RELEASE]    ... 92 common frames omitted

Since Redis doesn't allow querying data in range as I've done, is there a way to retrieve the data in a date range?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>