Skip to main content
This page describes how to integrate FalkorDB with Spring Data using spring-data-falkordb.

Overview

Spring Data FalkorDB provides JPA-style object-graph mapping for FalkorDB, enabling developers to use familiar Spring Data patterns and annotations to work with graph databases. This library makes it easy to build high-performance graph-based applications using Spring’s data access framework.

Key Features

  • JPA-style Annotations: Use familiar @Node, @Relationship, @Id, @Property annotations
  • Repository Abstractions: Implement FalkorDBRepository<T, ID> for automatic CRUD operations
  • Derived Query Methods: Full support for Spring Data query methods like findByName, findByAgeGreaterThan, etc.
  • Custom Queries: Write Cypher queries with @Query annotation and named parameters
  • Auto-Configuration: Enable repositories with @EnableFalkorDBRepositories
  • Object-Graph Mapping: Automatic conversion between Java objects and FalkorDB graph structures
  • Transaction Support: Built on Spring’s robust transaction management
  • High Performance: Leverages FalkorDB’s speed with the official JFalkorDB Java client

Getting Started

Installation

Add the following dependencies to your project:

Maven

Gradle

Entity Mapping

Define your graph entities using Spring Data annotations:

Repository Interface

Create repository interfaces extending FalkorDBRepository:

Configuration

Configure the FalkorDB connection in your Spring application:

Service Usage

Use repositories and templates in your service classes:

Supported Annotations

@Node

Marks a class as a graph node entity:

@Id

Marks the entity identifier:

@Property

Maps fields to graph properties:

@Interned

Marks string properties as low-cardinality, applying FalkorDB’s intern() function to optimize storage:
The @Interned annotation is useful for string properties that have a limited set of possible values (low cardinality). When a property is marked with @Interned, FalkorDB’s intern() function is automatically applied when writing to the database, which keeps only a single copy of frequently repeated string values, optimizing storage and query performance. Use cases:
  • Status codes (ACTIVE, INACTIVE, PENDING)
  • Country/region codes
  • Categories and types
  • Enum-like string values
  • Any string with a limited vocabulary

@Relationship

Maps relationships between entities:

Repository Query Methods

Spring Data FalkorDB supports two types of queries:

1. Derived Query Methods (Automatically Implemented)

Define methods following Spring Data naming conventions, and the implementation is generated automatically:

Query Keywords

  • findBy...: Find entities matching criteria
  • countBy...: Count entities matching criteria
  • existsBy...: Check if entities exist matching criteria
  • deleteBy...: Delete entities matching criteria
  • findFirstBy... / findTopNBy...: Limit results

Supported Comparison Operations

2. Custom Cypher Queries with @Query

Write custom Cypher queries for complex operations:

Query Method Examples

Twitter Integration Example

The library includes a comprehensive Twitter-like integration test that demonstrates real-world usage patterns. This example creates a social graph with users, tweets, follows, and hashtags.

Entity Examples

TwitterUser Entity

Tweet Entity

Advanced Configuration

Connection Pool Settings

Custom Converters

Transaction Configuration

Reference

Frequently Asked Questions

It supports JPA-style annotations including @Node, @Relationship, @Id, @Property, and @Query for custom Cypher queries. Use @EnableFalkorDBRepositories to activate auto-configuration.
Create an interface extending FalkorDBRepository<T, ID> where T is your entity class annotated with @Node and ID is the identifier type. Spring Data automatically provides CRUD operations.
Yes, it fully supports Spring Data derived query methods like findByName, findByAgeGreaterThan, findByNameContaining, etc. The framework automatically generates the appropriate Cypher queries.
Add spring-data-falkordb (groupId: org.springframework.data) and jfalkordb (groupId: com.falkordb) to your pom.xml. Check the repository for the latest versions.
Yes, Spring Data FalkorDB includes built-in transaction support via FalkorDBTransactionManager. Enable it with @EnableTransactionManagement and use @Transactional annotations on your service methods.