Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?


Failed to load latest commit information.
Latest commit message
Commit time

MIT License Build Status codecov

We have deprecated Spring Data Gremlin. We recommend that you use the TinkerPop driver to query Cosmos DB with Gremlin API or use azure-spring-boot-starter-cosmos to query Cosmos DB with Spring Data SQL API. If you would like us to continue supporting Spring Data Gremlin, please tell us how you are using Spring Data Gremlin for Cosmos DB and how important it is to you, by voting on this issue with the thumbs up emoji.

Spring Data Gremlin

Spring Data Gremlin provides initial Spring Data support for those databases using Gremlin query language. With annotation oriented programming model, it simplified the mapping to the database entity. It also provides supports for basic and custom query.

This project works with any Gremlin-compatible data store, and also with Azure Cosmos DB. Cosmos is a globally-distributed database service that allows developers to work with data using a variety of standard APIs, such as Graph, MongoDB, and SQL. Spring Data Gremlin provides a delightful experience to interact with Azure Cosmos DB Graph API.

Spring Data Version Support

Version mapping between spring boot and spring-data-gremlin:

Spring boot version spring-data-gremlin version
version Maven Central
version Maven Central
version Maven Central
version Maven Central


Welcome To Contribute

Contribution is welcome. Please follow this instruction to contribute code.

Sample Code

Please refer to sample project here.

Spring data version support

This repository only supports Spring Data 2.x.

Feature List

  • Spring Data CRUDRepository basic CRUD functionality
    • save
    • findAll
    • findById
    • deleteAll
    • deleteById
  • Spring Data @Id annotation. There're 2 ways to map a field in domain class to id field of a database entity.
    • annotate a field in domain class with @Id
    • set name of this field to id
  • Default annotaion
    • @Vertex maps an Object to a Vertex
    • @VertexSet maps a set of Vertex
    • @Edge maps an Object to an Edge
    • @EdgeSet maps to a set of Edge
    • @EdgeFrom maps to the head Vertex of an Edge
    • @EdgeTo maps to the tail Vertex of an Edge
    • @Graph maps to an Object to a Graph
  • Supports advanced operations
    • <T> T findVertexById(Object id, Class<T> domainClass);
    • <T> T findEdgeById(Object id, Class<T> domainClass);
    • <T> boolean isEmptyGraph(T object)
    • long vertexCount()
    • long edgeCount()
  • Supports Spring Data custom query find operation, e.g., findByAFieldAndBField
  • Supports any class type in domain class including collection and nested type.

Quick Start

Add the dependency

spring-data-gremlin is published on Maven Central Repository.
If you are using Maven, add the following dependency.


Setup Configuration

Setup application.yml file.(Use Azure Cosmos DB Graph as an example.)

  endpoint: url-of-endpoint 
  port: 443
  username: /dbs/your-db-name/colls/your-collection-name
  password: your-password
  telemetryAllowed: true # set false to disable telemetry

Define an entity

Define a simple Vertex entity with @Vertex.

public class Person {

    private String id;

    private String name;

    private String age;


Define a simple Edge entity with @Edge.

public class Relation {

    private String id;

    private String name;

    private Person personFrom;

    private Person personTo;


Define a simple Graph entity with @Graph.

public class Network {

    private String id;

    public Network() {
        this.edges = new ArrayList<Object>();
        this.vertexes = new ArrayList<Object>();

    private List<Object> edges;

    private List<Object> vertexes;

Create repositories

Extends DocumentDbRepository interface, which provides Spring Data repository support.

import GremlinRepository;
import org.springframework.stereotype.Repository;

public interface PersonRepository extends GremlinRepository<Person, String> {
        List<Person> findByName(String name); 

findByName method is custom query method, it will find the person with the name property.

Create an Application class

Here create an application class with all the components

public class SampleApplication implements CommandLineRunner {

    private PersonRepository repository;

    public static void main(String[] args) {, args);

    public void run(String... var1) throws Exception {

        private final Person testUser = new Person("PERSON_ID", "PERSON_NAME", "PERSON_AGE");



Autowired UserRepository interface, then can do save, delete and find operations. Spring Data Azure Cosmos DB uses the DocumentTemplate to execute the queries behind find, save methods. You can use the template yourself for more complex queries.

Filing Issues

If you encounter any bug, please file an issue here.

To suggest a new feature or changes that could be made, file an issue the same way you would for a bug.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.


This project collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more.


We are in the process of deprecating Spring Data Gremlin. -- Provide generic annotation oriented programming form based on gremlin for graph database




Code of conduct

Security policy





No packages published