Get Started What is a GraphDB? GraphDB vs RDBMS GraphDB vs NOSQL Language Drivers Cypher Cypher Basics Build a Recommendation Engine Cypher Refcard Data Modeling Graph Data Modeling Guidelines Working with Data Neo4j Browser Visualization Importing Data into Neo4j Graph… Learn More »
If you are a Java developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive it will introduce the different APIs and link to the relevant resources.
You should be familiar with the graph database concepts and the property graph model. Having installed Neo4j and tried out our Cypher Query language helps too. For working with Neo4j please use JDK 7 and your favorite IDE.
Neo4j for Java Developers
Neo4j offers a rich set of integration possibilities for Java or JVM-language developers.
There are two ways of using Neo4j from the JVM. The standalone Neo4j-Server can be installed on any machine and then accessed via its HTTP API. You can use any REST-library you choose for any JVM language. The dedicated Neo4j drivers go beyond that by offering comprehensive APIs for integrating with graph based applications.
But you can also run Neo4j embedded in your JVM process, much like HSQL or Derby. This is great for unit testing, but also for high performance / no-network setups. If you use Neo4j embedded you can use the Neo4j Core-Java-API directly. Besides an object oriented approach to the graph database, working with Nodes, Relationships and Paths, it also offers highly customizable high-speed traversal- and graph-algorithm implementations. You can also choose from any useful drivers wrapping that API, which exist for either for specific programming languages or that add interesting functionality.
As a JVM developer you are also on the bright side when it comes to inserting large amounts of data into Neo4j. With its non-transactional, low-level batch-insertion API it can ingest millions of nodes and relationships in just seconds.
Follow the guides below to get you started.
The Example Project
It is a small one page webapp for our movies database. The front-end is the same for all drivers, just the backends show you how to connect to Neo4j from the different languages and drivers.
Using Neo4j Server with JDBC
Being a Java developer you’re probably familiar with JDBC as a way to work with relational databases, either directly or via abstractions like Spring’s
JDBCTemplate or MyBatis. Also many tools for ETL, Business Intelligence and data management use JDBC drivers to interact with relational databases.
As Cypher, like SQL is a textual parametrizable query language that can return tabular results, it was possible for us to support the JDBC APIs, and make a Neo4j-JDBC driver available. More details on how to use it can be found with our example project for Java-JDBC. There we implement the backend as minimal Java webapp that leverages Neo4j-JDBC to connect to Neo4j Server.
Extending Neo4j Server with a Server Extension
A great way of accessing the high performance graph database directly from your Java code is to write a Neo4j Server extension. Then you get the double benefit of easy deployment and high performance database access.
A Server extension provides a Jersey JAX-RS REST endpoint with a protocol and granularity that you control, you use it to send and receive data structures of your domain.
After declaring the dependencies to Neo4j and Neo4j-Server-APIs you can create REST-resources that are deployed by Jersey at startup. Within those resources you can get the
ExecutionEngine injected and use all Java APIs as well as executing Cypher directly. The path-finding and traversal APIs are also available.
The results of your graph operations are then collected and rendered as the format you want to expose, e.g. JSON, XML, plain text or binary.
The example project shows how you would do that for our movie application endpoints.
Using Spring Boot with JDBC
Spring Boot is a rapid application development infrastructure that allows you to quickly write Spring based applications with little setup and configuration.
Here we use a simple Spring-Boot WebMVC and -JDBC application to provide a backend for our movie application.
It just uses the well known APIs of
JdbcTemplate to do the Job.
More details can be found in the example project.
Using Spring Data Neo4j
Spring Data Neo4j was the first Spring Data project and enables convenient integration of Neo4j in your Spring based application. It provides object-graph mapping functionality and other features common to the Spring Data projects.
To use Neo4j with Spring Data Neo4j, you just add the dependency to your build setup. After setting up a simple Java based Spring configuration, and annotating your
@RelationshipEntity , you can use
Neo4jTemplate to access Neo4j APIs and object graph mapping functionality. Additionally you can leverage the convenient Spring-Data repositories to get interface based DAO implementations injected into your Spring Components.
|The current version of Spring Data Neo4j works best with an embedded Neo4j database. To achieve highest-performance Neo4j-Server integration move your SDN persistence layer into an Server Extension.|
The example uses Spring-Boot with Spring-Data-Neo4j and Spring-Data-REST and an additional RestMVCController.
See the example project for further details.
Author: Stefan Armbruster
A plugin that integrates the Neo4j graph database into Grails, providing a GORM API onto it
Author: Michael Klishin, Rohig Aggarval
An idiomatic, feature rich Clojure client which supports (almost) all Neo4J REST API features and is constantly tested against bleeding edge server changes, like the Cypher language improvements.
Author: Jozef Wagner Clojure wrapper for Neo4j, a graph database, in embedded JVM mode.
Author: Wes Freeman
A Cypher-oriented Scala library modeled after the Play! framework’s Anorm library.
Author: Christopher Schmidt
The Neo4j Scala wrapper library allows you use Neo4j open source graph database through a domain-specific language.
Authors: Davide D’Alto, Gunnar Moelling, Emmanuel Bernard
Hibernate Object/Grid Mapper (OGM) with Neo4j Support.
Author: Andy Jefferson
datanucleus-neo4j provides persistence of Java objects to Neo4j. It builds on top of the basic persistence provided by datanucleus-core.
Sign up to find out more about Neo4j's upcoming events & meetups.