#Springboot Elasticsearch findBy question

28 messages · Page 1 of 1 (latest)

hasty mountain
#

I'm trying to do the following in my repository

public interface RecordRepository extends ElasticsearchRepository<MapRecord, String> {
    List<MapRecord> findAllByMapId(UUID mapId);
}

I checked and the UUID passed is valid but I keep getting the following error
2024-08-28T07:14:06.629-04:00 ERROR 71164 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.UUID] for value [uRammJEBFLu3c54-2L-g]] with root cause

java.lang.IllegalArgumentException: Invalid UUID string: uRammJEBFLu3c54-2L-g

Even though the UUID prints out to console as
7bd634bc-59b3-4526-9ad4-cbd1a8f76f26

Also, mapId is not @Id it's just a copy of another repo's id to use for requests, so stored as any other class variable

gentle geodeBOT
#

This post has been reserved for your question.

Hey @hasty mountain! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

sage wolf
#

Can you show the entry in the DB as well as the entity class?

hasty mountain
#
package com.offthetop.surfmania.backend.model;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

import java.util.UUID;

@Document(indexName = "records")
public class MapRecord {
    @Id
    private UUID recordId;

    private UUID mapId;

    private String playerName;

    private String playerIp;

    private String country;

    private String record;

    public UUID getRecordId() {return recordId;}
    public UUID getMapId() {return mapId;}
    public String getPlayerName() {return playerName;}
    public String getCountry() {return country;}
    public String getRecord() {return record;}
    public void setMapId(UUID mapId) {this.mapId = mapId;}
    public void setPlayerName(String playerName) {this.playerName = playerName;}
    public void setCountry(String country) {this.country = country;}
    public void setRecord(String record) {this.record = record;}
    public void setPlayerIp(String playerIp) {this.playerIp = playerIp;}
    public String getPlayerIp() {return playerIp;}
}
sage wolf
#

Does the error occur when saving or when retrieving?

#

Can you show the relevant code?

#

If it is retrieving, the entry should be present in elasticsearch

hasty mountain
#

before that the uuid.ToString returns the expected value

#

seems like an elasticsearch limitation but i'm not sure

#

and right, it is retreiving, here's what the entry looks like (taken from swagger)

{
  "recordId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "mapId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "playerName": "string",
  "playerIp": "string",
  "country": "string",
  "record": "string"
}
sage wolf
#

ok

#

Are there other entries?

#

Is that really the whole entry?

#

Can you show the full stack trace?

hasty mountain
# sage wolf Is that really the whole entry?

maybe there's another issue, seems like recordId is null there

{
  "recordId": null,
  "mapId": "7bd634bc-59b3-4526-9ad4-cbd1a8f76f23",
  "playerName": "string",
  "playerIp": "0:0:0:0:0:0:0:1",
  "country": null,
  "record": null
}

(post response)

#

yeah there should be a constructor setting recordid, will see if that's the issue

sage wolf
#

Can you show your DefaultRecordService?

hasty mountain
# sage wolf Can you show your `DefaultRecordService`?

the conversion to string is a test i did, it was without before

@Service
public class DefaultRecordService implements RecordService {
    private final RecordRepository recordRepository;

    private final ElasticsearchTemplate elasticsearchTemplate;

    public DefaultRecordService(RecordRepository recordRepository, ElasticsearchTemplate elasticsearchTemplate) {
        this.recordRepository = recordRepository;
        this.elasticsearchTemplate = elasticsearchTemplate;
    }

    public MapRecord create(MapRecord mapRecord) {
        return recordRepository.save(mapRecord);
    }

    public List<MapRecord> findAllByMapId(String id) {
        System.out.println(id);
        System.out.println(UUID.fromString(id));
        return recordRepository.findAllByMapId(UUID.fromString(id));
    }
}
sage wolf
#

which isn't valid

hasty mountain
#

yeah possibly, was just clearing entries, will test with clean entries

#

@sage wolf that was it, thanks a lot, will close this soon

gentle geodeBOT