如果我尝试简单
thingNode.setProperty("uuid", thing.getId());
我明白了
java.util.UUID] is not a supported property value
然而,将128位UUID存储为36个字符的字符串将非常浪费。 如果我将UUID拆分存储到单独的属性中
thingNode.setProperty("uuid-begin", thing.getId().getMostSignificantBits()); thingNode.setProperty("uuid-end", thing.getId().getLeastSignificantBits());看来我只能在单个属性上创建索引 ,并且必须将UUID的两位以某种方式连接到一个属性中。 如上所述,由于存储空间非常低效,因此不希望使用字符串。 有任何想法吗?
If I try the simple
thingNode.setProperty("uuid", thing.getId());
I get
java.util.UUID] is not a supported property value
Yet it would be incredibly wasteful to store a 128-bit UUID as a 36-character string. If I store the UUID split apart into separate properties
thingNode.setProperty("uuid-begin", thing.getId().getMostSignificantBits()); thingNode.setProperty("uuid-end", thing.getId().getLeastSignificantBits());It appears I can only create an index on a single property, and would have to concatenate the two bits of the UUID somehow into one property. As mentioned above, strings are undesirable due to highly inefficient storage space. Any ideas?
最满意答案
我过去曾使用过以下代码片段。 由于UUID是“一件事”,因此将其存储到一个属性中是一个不错的主意。 正如您已经提到的,索引总是建立在一个属性上。
final StringBuilder sb = new StringBuilder(); sb.append(Long.toHexString(uuid.getMostSignificantBits())) .append(Long.toHexString(uuid.getLeastSignificantBits())); String uuidAsString = sb.toString(); node.setProperty("uuid", uuidAsString);请注意,有一个现成的解决方案来管理Neo4j中的uuids: https : //github.com/graphaware/neo4j-uuid
I've used the following snippet for this in the past. Since a UUID is "one thing" it's a good idea to store it into one property. As you've already mentioned a index is always build on one property.
final StringBuilder sb = new StringBuilder(); sb.append(Long.toHexString(uuid.getMostSignificantBits())) .append(Long.toHexString(uuid.getLeastSignificantBits())); String uuidAsString = sb.toString(); node.setProperty("uuid", uuidAsString);Please note that there is a ready-to-go solution for managing uuids in Neo4j: https://github.com/graphaware/neo4j-uuid
更多推荐
发布评论