0

Is it possible to use auto generated id in Spring Data Gemfire? for example, if I have a class called MyGemfire

@region("myregion")
class MyGemfire{

    @Id
    @generatedValue????// if it is not possible what method I have to use to generate id in auto increment fashion?
    Long id;
    String name;
    ...
}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Ezd
  • 331
  • 3
  • 10

1 Answers1

1

From a quick look at SimpleGemfireRepository it doesn't look like the repository is generating an ID:

@Override
public <U extends T> U save(U entity) {
    ID id = entityInformation.getId(entity).orElseThrow(
        () -> newIllegalArgumentException("ID for entity [%s] is required", entity));

    template.put(id, entity);

    return entity;
}

Also, this question and its answer suggest there is no ID generation in Gemfire itself.

So what you should do is to create your ID yourself. For example, it should be possible to have two constructors one taking an ID and the othe not taking an ID but generating it. A UUID would be the obvious choice. If you are bound to Long values, you probably have to roll your own algorithm.

To make it obvious to Spring Data which constructor to use when loading instances, you can use the @PersistenceConstructor annotation.

Community
  • 1
  • 1
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348