I have the below event handler which i save an user in the cache using redis.
@Component
public class UserEventHander {
private final RedisTemplate<String, User> redisTemplate;
private final HashOperations<String, String, User> hashOperations;
public UserEventHander(RedisTemplate<String, User> redisTemplate) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
}
@EventHandler
public void on(UserCreate evt) {
final User user = mapper.toUser(evt);
hashOperations.putIfAbsent(User.class.getSimpleName(), user.getUserId(), user);
}
}
In the query handler when i tried to get the user by id like below, i get an error
@Component
public class UserQueryHandler {
private final RedisTemplate<String, User> redisTemplate;
private final HashOperations<String, String, User> hashOperations;
public UserQueryHandler(RedisTemplate<String, User> redisTemplate) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
}
@QueryHandler
public User on(GetUserById query) {
return hashOperations.get(User.class.getSimpleName(), query.getUserId());
}
}
the error
org.axonframework.axonserver.connector.query.AxonServerRemoteQueryHandlingException: An exception was thrown by the remote message handling component: class java.util.LinkedHashMap cannot be cast to class com.test.query.domain.User (java.util.LinkedHashMap is in module java.base of loader ‘bootstrap’; com.test.query.domain.User is in unnamed module of loader ‘app’)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetUserById {
private String userId;
}
@Document
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder(toBuilder = true)
public class User {
@Id
private String userId;
private String fisrtName;
private String lastName;
}