Reputation: 1824
Based on Spring Data Redis guide, and having the following defined:
Model
@RedisHash("positions")
public class Position {
@Id
private String id;
@GeoIndexed
private Point coordinates;
//...
}
Connection
@Configuration
public class RedisConfig {
@Bean
public RedisConnectionFactory lettuceConnectionFactory() {
return new LettuceConnectionFactory("localhost", 6379);
}
@Bean
public RedisTemplate<String, Position> redisTemplate() {
final RedisTemplate<String, Position> template = new RedisTemplate<String, Position>();
template.setConnectionFactory(lettuceConnectionFactory());
return template;
}
}
I want to query for positions by its coordinates, that is why I defined the following repository:
Repository
public interface PositionRepository extends CrudRepository<Position, String> {
List<Position> findByCoordinates(Point point);
//...
}
but calling that method results in org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.geo.Point] to type [byte[]]
How can I define/implement that query?
Upvotes: 0
Views: 2442
Reputation: 18129
You need to use the Near
keyword to indicate it's a geo query.
Spring Data derives from query methods the property to match and its actual match mode. There are several match modes and the default is exact (simple property) matching by comparing the criteria against the stored value.
Change your code to
public interface PositionRepository extends CrudRepository<Position, String> {
List<Position> findByCoordinatesNear(Point point);
}
to execute a Geo query.
It's not really relevant how you annotated your object as you're specifying query methods from the repository perspective.
See also:
Upvotes: 1