package com.huajun.kgbuilder.util;

import org.neo4j.ogm.id.IdStrategy;

/**
 * 于吉利
 * 2021-08-26
 * Neo4j自定义主键策略
 */
public class Neo4JCustomIdStrategy implements IdStrategy {
    @Override
    public Object generateId(Object o) {
        return o.hashCode();
    }

}

@Id
@GeneratedValue(strategy = Neo4JCustomIdStrategy.class)
private String id;






 以上只适用非cloud项目,引用的文件是

import org.neo4j.ogm.id.IdStrategy;




spring cloud Alibaba 微服务项目引用
import org.springframework.data.neo4j.core.schema.IdGenerator
/*
 * @Copyright (c) 2021. 于吉利 All Rights Reserved
 * @Author: 于吉利
 * @Function:
 * @Date: 2021/8/27 上午11:50
 * @version:1.0
 * @Changes:
 * @Description:
 *
 */

package com.huajun.kgbuilder.util;

import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.data.neo4j.core.schema.IdGenerator;
import org.springframework.util.StringUtils;

public class SequenceGenerator implements IdGenerator<String> {

    private final AtomicInteger sequence = new AtomicInteger(0);

    @Override
    public String generateId(String primaryLabel, Object entity) {
        return StringUtils.uncapitalize(primaryLabel) +
                "-" + sequence.incrementAndGet();
    }

}

 










相关文章:

  • 2022-12-23
  • 2021-10-18
  • 2022-01-23
  • 2021-05-01
  • 2021-07-24
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案