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,@Propertyannotations - 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
@Queryannotation 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 extendingFalkorDBRepository:
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’sintern() function to optimize storage:
@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 criteriacountBy...: Count entities matching criteriaexistsBy...: Check if entities exist matching criteriadeleteBy...: Delete entities matching criteriafindFirstBy.../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
What annotations does Spring Data FalkorDB support?
What annotations does Spring Data FalkorDB support?
It supports JPA-style annotations including
@Node, @Relationship, @Id, @Property, and @Query for custom Cypher queries. Use @EnableFalkorDBRepositories to activate auto-configuration.How do I define a repository for my graph entities?
How do I define a repository for my graph entities?
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.Does Spring Data FalkorDB support derived query methods?
Does Spring Data FalkorDB support derived query methods?
Yes, it fully supports Spring Data derived query methods like
findByName, findByAgeGreaterThan, findByNameContaining, etc. The framework automatically generates the appropriate Cypher queries.What dependencies do I need in my Maven project?
What dependencies do I need in my Maven project?
Add
spring-data-falkordb (groupId: org.springframework.data) and jfalkordb (groupId: com.falkordb) to your pom.xml. Check the repository for the latest versions.Does it support transactions?
Does it support transactions?
Yes, Spring Data FalkorDB includes built-in transaction support via
FalkorDBTransactionManager. Enable it with @EnableTransactionManagement and use @Transactional annotations on your service methods.