2017-04-26 78 views
0

是否可以在Spring Data Gemfire中使用自动生成的ID? 例如,如果我在SimpleGemfireRepository有一个名为MyGemfireSpring Gemfire实体类ID生成

@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; 
    ... 
} 

回答

1

从快看一流的IT并不像仓库已生成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; 
} 

此外,this question and its answer建议有Gemfire本身没有生成身份证。

所以你应该做的是自己创建你的ID。例如,应该有两个构造函数可以带一个ID并且不带一个ID但是生成它。 A UUID将是明显的选择。如果你被绑定到Long的值,你可能不得不推出你自己的算法。

为了让Spring Data显而易见加载实例时使用哪个构造函数,您可以使用@PersistenceConstructor注释。

+0

谢谢。我使用UUID生成器。 – Ezd