### Cypher pattern comprehension example Source: https://github.com/neo4j/neo4j-ogm/blob/master/CHANGES.adoc A Cypher query demonstrating pattern comprehension where the return structure is now preserved as a collection of arrays. ```cypher MATCH (n:Movie{title:'Pulp Fiction'}) return n, [(n)-[r:UNKNOWN]-(p) | [r,p]] as relAndNode ``` -------------------------------- ### Relationship Event Example Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Demonstrates how deleting an object that has a relationship with another object triggers events for both. Note that the owning object may fire SAVE events to reflect the relationship change. ```java Folder folder = new Folder(); Document a = new Document("a"); folder.addDocuments(a); session.save(folder); // When we delete the document, the following events will be fired // - PRE_DELETE a // - POST_DELETE a // - PRE_SAVE folder <1> // - POST_SAVE folder session.delete(a); ``` -------------------------------- ### Example of nested list structure Source: https://github.com/neo4j/neo4j-ogm/blob/master/CHANGES.adoc Represents a nested list structure that was previously flattened in versions prior to 3.2.32. ```text [[n0, n1, n2], [n3], [n4], [n5, n6]] ``` -------------------------------- ### Reviewer Entity with OGM Annotations Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/annotations.adoc Example of a Java entity class annotated for Neo4j OGM mapping. It includes annotations for primary key, property mapping, and node relationships. ```java public class Reviewer { @Id @GeneratedValue Long id; @Property("summary") String review; int rating; @EndNode Movie movie; @StartNode Person person; } ``` -------------------------------- ### Create SessionFactory with Driver Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/connecting.adoc Instantiate a SessionFactory by providing a Driver instance and the packages to scan for domain classes. The SessionFactory should be created once during application startup. ```java SessionFactory sessionFactory = new SessionFactory(driver, "com.mycompany.app.domainclasses"); ``` -------------------------------- ### Create SessionFactory with Configuration Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/connecting.adoc Instantiate a SessionFactory by providing a Configuration object and the packages to scan for domain classes. The SessionFactory should be created once during application startup. ```java SessionFactory sessionFactory = new SessionFactory(configuration, "com.mycompany.app.domainclasses"); ``` -------------------------------- ### Create SessionFactory with Multiple Entity Packages Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/connecting.adoc Instantiate a SessionFactory by providing a Configuration object and multiple packages to scan for domain classes. This allows for organizing domain models across different packages. ```java SessionFactory sessionFactory = new SessionFactory(configuration, "first.package.domain", "second.package.domain",...); ``` -------------------------------- ### Undirected Relationship Example Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Models a relationship where direction is not important, ensuring only one relationship of the specified type exists between two entities and is navigable from either side. Use Relationship.Direction.UNDIRECTED. ```java @NodeEntity class Person { private Long id; @Relationship(type="OWNS") private Car car; ``` -------------------------------- ### Load Configuration from Filesystem Properties File Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Use FileConfigurationSource to load configuration from a properties file on the filesystem. ```java ConfigurationSource props = new FileConfigurationSource("/etc/my.properties"); Configuration configuration = new Configuration.Builder(props).build(); ``` -------------------------------- ### Configure SessionFactory with Neo4j Connection Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/configuration.adoc Instantiate a SessionFactory by providing the database URI, credentials, and the package to scan for domain classes. ```java Configuration configuration = new Configuration.Builder() .uri("neo4j://localhost:7687") .credentials("neo4j", "verysecret") .build(); SessionFactory sessionFactory = new SessionFactory(configuration, "org.neo4j.ogm.example"); ``` -------------------------------- ### Credentials Configuration using Properties File Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure username and password for Bolt driver authentication using a properties file. ```properties username="user" password="password" ``` -------------------------------- ### MovieService Implementation with SessionFactory Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/session.adoc Provides the implementation for movie operations using Neo4j OGM SessionFactory and Sessions. Demonstrates session instantiation, entity loading, saving, and querying. ```java public class MovieService { final SessionFactory sessionFactory; public MovieService() { Configuration config = new Configuration.Builder() .uri("neo4j://localhost:7687") .credentials("neo4j", "verysecret") .build(); this.sessionFactory = new SessionFactory(config, "org.neo4j.ogm.example"); } Movie findMovieByTitle(String title) { Session session = sessionFactory.openSession(); return Optional.ofNullable( session.queryForObject(Movie.class, "MATCH (m:Movie {title:$title}) return m", Map.of("title", title))) .orElseThrow(() -> new MovieNotFoundException(title)); } public List allMovies() { Session session = sessionFactory.openSession(); return new ArrayList<>(session.loadAll(Movie.class)); } Movie updateTagline(String title, String newTagline) { Session session = sessionFactory.openSession(); Movie movie = session.queryForObject(Movie.class, "MATCH (m:Movie{title:$title}) return m", Map.of("title", title)); Movie updatedMovie = movie.withTagline(newTagline); session.save(updatedMovie); return updatedMovie; } } ``` -------------------------------- ### Basic Bolt Driver Configuration with Connection Pool Size Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure the Bolt driver URI and connection pool size using properties file. ```properties URI=bolt://neo4j:password@localhost connection.pool.size=150 ``` -------------------------------- ### Configure Encryption and Trust Strategy Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Set encryption level and trust strategy using Java Configuration Builder. Ensure trust certificate file is provided if a trust strategy is specified. ```java Configuration config = new Configuration.Builder() ... .encryptionLevel("REQUIRED") .trustStrategy("TRUST_ON_FIRST_USE") .trustCertFile("/tmp/cert") .build(); ``` -------------------------------- ### Load Configuration from Classpath Properties File Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Use ClasspathConfigurationSource to load configuration from a properties file located on the classpath. ```java ConfigurationSource props = new ClasspathConfigurationSource("my.properties"); Configuration configuration = new Configuration.Builder(props).build(); ``` -------------------------------- ### Configure Neo4j-OGM Dependencies Source: https://github.com/neo4j/neo4j-ogm/blob/master/README.adoc Include the core library and the Bolt driver in your project build configuration. ```xml org.neo4j neo4j-ogm-core {version} org.neo4j neo4j-ogm-bolt-driver {version} ``` ```gradle dependencies { compile 'org.neo4j:neo4j-ogm-core:{version}' compile 'org.neo4j:neo4j-ogm-bolt-driver:{version}' } ``` -------------------------------- ### Basic Bolt Driver Configuration with Connection Pool Size (Java) Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure the Bolt driver URI and connection pool size programmatically using Java. ```java Configuration configuration = new Configuration.Builder() .uri("bolt://neo4j:password@localhost") .setConnectionPoolSize(150) .build() ``` -------------------------------- ### Credentials Configuration using Java Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure username and password for Bolt driver authentication programmatically using Java. ```java Configuration configuration = new Configuration.Builder() .uri("bolt://localhost") .credentials("user", "password") .build() ``` -------------------------------- ### Configure Logback for Neo4j-OGM Logging Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/testing.adoc This configuration file sets up Logback to display Neo4j-OGM logs. Set the 'org.neo4j.ogm' logger level to 'info' to see Cypher statements or 'debug' for more detailed diagnostics. Ensure this file is named 'logback-test.xml' and placed in your test resources folder. ```xml %d %5p %40.40c:%4L - %m%n ``` -------------------------------- ### Registering and Disposing EventListener Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Demonstrates how to register a custom EventListener on a session or SessionFactory and how to remove it. ```java class AddUuidPreSaveEventListener implements EventListener { void onPreSave(Event event) { DomainEntity entity = (DomainEntity) event.getObject(); if (entity.getId() == null) { entity.setUUID(UUID.randomUUID()); } } void onPostSave(Event event) { } void onPreDelete(Event event) { } void onPostDelete(Event event) { } EventListener eventListener = new AddUuidPreSaveEventListener(); // register it on an individual session session.register(eventListener); // remove it. session.dispose(eventListener); // register it across multiple sessions sessionFactory.register(eventListener); // remove it. sessionFactory.deregister(eventListener); ``` -------------------------------- ### Enable Eager Connection Verification Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Forces OGM to connect to the Neo4j server on application startup. This is useful for ensuring the database is accessible immediately, overriding the default lazy connection behavior. This setting is only valid for Bolt drivers. ```java Configuration config = new Configuration.Builder() .verifyConnection(true) .build(); ``` -------------------------------- ### Load All Entities with Pagination Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Loads all entities of a given type with specified pagination parameters. Requires the Session object and Pagination class. ```java Iterable worlds = session.loadAll(World.class, new Pagination(pageNumber,itemsPerPage), depth) ``` -------------------------------- ### Provide Bolt Driver Instance to SessionFactory Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure Neo4j-OGM by providing an already configured native Neo4j Java driver instance to the SessionFactory. ```java org.neo4j.driver.Driver nativeDriver = ...; Driver ogmDriver = new BoltDriver(nativeDriver); new SessionFactory(ogmDriver, ...); ``` -------------------------------- ### Load All Entities with Sorting and Pagination Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Loads all entities of a given type, applying sorting and pagination. Note that Neo4j-OGM does not yet support sorting and paging on custom queries. ```java Iterable worlds = session.loadAll(World.class, new SortOrder().add("name"), new Pagination(pageNumber,itemsPerPage)) ``` -------------------------------- ### Load All Entities with Sorting and Paging Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Loads all entities of a given type with both sorting and pagination applied. This combines the functionality of sorting and paging for comprehensive result control. ```java Iterable worlds = session.loadAll(World.class, new Pagination(pageNumber, itemsPerPage), new SortOrder().add("name"), depth); ``` -------------------------------- ### Persisting an Entity with Neo4j-OGM Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Demonstrates how to save a new entity to the Neo4j database using the Session.save() method. Ensure the entity class is annotated with @NodeEntity. ```java @NodeEntity public class Person { private String name; public Person(String name) { this.name = name; } } // Store Michael in the database. Person p = new Person("Michael"); session.save(p); ``` -------------------------------- ### Explicit Transaction Management with Try-With-Resources Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/transactions.adoc Manage transactions explicitly by calling beginTransaction(), commit(), or rollback(). Ensure transactions are always closed using a try-with-resources block. ```java try (Transaction tx = session.beginTransaction()) { Person person = session.load(Person.class,personId); Concert concert= session.load(Concert.class,concertId); Hotel hotel = session.load(Hotel.class,hotelId); buyConcertTicket(person,concert); bookHotel(person, hotel); tx.commit(); } catch (SoldOutException e) { tx.rollback(); } ``` -------------------------------- ### Implementing EventListenerAdapter for PreSave Events Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Shows how to extend EventListenerAdapter to handle only the onPreSave event, overriding the default no-op implementation. ```java class PreSaveEventListener extends EventListenerAdapter { @Override void onPreSave(Event event) { DomainEntity entity = (DomainEntity) event.getObject(); if (entity.id == null) { entity.UUID = UUID.randomUUID(); } } } ``` -------------------------------- ### Executing Custom Cypher Queries Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc The Session allows execution of arbitrary Cypher queries via its `query` and `queryForObject` methods. Use `query` for tabular results and `queryForObject` for entities. ```APIDOC ## Cypher queries Cypher is Neo4j's powerful query language. It is understood by all the different drivers in Neo4j-OGM which means that your application code should run identically, whichever driver you choose to use. The `Session` also allows execution of arbitrary Cypher queries via its `query` and `queryForObject` methods. Cypher queries that return tabular results should be passed into the `query` method which returns an `Result`. This consists of `QueryStatistics` representing statistics of modifying cypher statements if applicable, and an `Iterable>` containing the raw data, which can be either used as-is or converted into a richer type if needed. The keys in each `Map` correspond to the names listed in the return clause of the executed Cypher query. `queryForObject` specifically queries for entities and as such, queries supplied to this method must return nodes and not individual properties. Query methods that retrieve mapped objects may be used in cases where the query generated by load strategy does not have sufficient performance. Such queries should return nodes and optionally relationships. For a relationship to be mapped both start and end node must be returned. Query methods returning particular domain type collect the result from all result columns and nested structures in these (e.g. collected lists, maps etc..) and return as single `Iterable`. Use `Result Session.query(java.lang.String, java.util.Map)` to retrieve only objects in particular column. [NOTE] ==== In the current version, custom queries do not support paging, sorting or a custom depth. In addition, it does not support mapping a path to domain entities, as such, a path should not be returned from a Cypher query. Instead, return nodes and relationships to have them mapped to domain entities. Modifications made to the graph via Cypher queries directly will not be reflected in your domain objects within the session. ==== ``` -------------------------------- ### Using a Single Filter Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/filters.adoc Loads all `Satellite` entities where the 'manned' property equals true. ```java Collection satellites = session.loadAll(Satellite.class, new Filter("manned", ComparisonOperator.EQUALS, true)); ``` -------------------------------- ### Loading DTOs Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Allows querying arbitrary data from Neo4j and combining the result into a wrapper object (DTO). ```APIDOC ## Loading DTOs It is possible to also query arbitrary data from Neo4j and make OGM combine the result in a wrapper object/DTO. To request a DTO, Neo4j-OGM offers ` List queryDto(String cypher, Map parameters, Class type)`. [INFO] ==== This API might get extended in the next minor/patch versions of Neo4j-OGM. ==== ``` -------------------------------- ### Tagging a Git Release Source: https://github.com/neo4j/neo4j-ogm/wiki/Release-Checklist Use this command to tag a specific release version in Git. Replace X.Y.Z with the actual version number. ```bash git tag -a vX.Y.Z -m "Released as vX.Y.Z" ``` -------------------------------- ### Persist and Load Entities Source: https://github.com/neo4j/neo4j-ogm/blob/master/README.adoc Use the SessionFactory to open a session for performing CRUD operations on domain entities. ```java //Set up the Session SessionFactory sessionFactory = new SessionFactory(configuration, "movies.domain"); Session session = sessionFactory.openSession(); Movie movie = new Movie("The Matrix", 1999); Actor keanu = new Actor("Keanu Reeves"); keanu.actsIn(movie); Actor carrie = new Actor("Carrie-Ann Moss"); carrie.actsIn(movie); //Persist the movie. This persists the actors as well. session.save(movie); //Load a movie Movie matrix = session.load(Movie.class, movie.getId()); for(Actor actor : matrix.getActors()) { System.out.println("Actor: " + actor.getName()); } ``` -------------------------------- ### Load All Entities with Sorting Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Loads all entities of a given type, sorted by a specified field. Requires the Session object and SortOrder class. ```java Iterable worlds = session.loadAll(World.class, new SortOrder().add("name"), depth) ``` -------------------------------- ### Gradle Dependencies for Neo4j-OGM Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/getting-started.adoc Add these dependencies to your build.gradle file to integrate Neo4j-OGM with the Bolt driver. ```groovy dependencies { compile 'org.neo4j:neo4j-ogm-core:{ogm-version}' runtime 'org.neo4j:neo4j-ogm-bolt-driver:{ogm-version}' } ``` -------------------------------- ### Map Dynamic Properties using @Properties Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Demonstrates using the @Properties annotation to map a Map field to dynamic properties of a node or relationship entity. ```java @NodeEntity public class Student { @Properties private Map properties = new HashMap<>(); @Properties private Map properties = new HashMap<>(); } ``` -------------------------------- ### Sorting and Paging Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Neo4j-OGM supports Sorting and Paging of results when using the Session object. The Session object methods take independent arguments for Sorting and Pagination. ```APIDOC ## Sorting and paging Neo4j-OGM supports Sorting and Paging of results when using the Session object. The Session object methods take independent arguments for Sorting and Pagination. .Paging [source, java] ---- Iterable worlds = session.loadAll(World.class, new Pagination(pageNumber,itemsPerPage), depth) ---- .Sorting [source, java] ---- Iterable worlds = session.loadAll(World.class, new SortOrder().add("name"), depth) ---- .Sort in descending order [source, java] ---- Iterable worlds = session.loadAll(World.class, new SortOrder().add(SortOrder.Direction.DESC,"name")) ---- .Sorting with paging [source, java] ---- ``` -------------------------------- ### Event Ordering in Collections Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Highlights that while PRE_ events precede POST_ events, the internal order of events within the same type (PRE_ or POST_) for a collection save is not guaranteed. ```java Document a = new Document("a"); Document b = new Document("b"); // Although the save order of objects is implied by the request, the PRE_SAVE event for `b` // may be fired before the PRE_SAVE event for `a`, and similarly for the POST_SAVE events. // However, all PRE_SAVE events will be fired before any POST_SAVE event. session.save(Arrays.asList(a, b)); ``` -------------------------------- ### Saving Connected Objects Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Demonstrates how saving a top-level object also triggers events for its connected objects, even if they are not explicitly saved. ```java Folder folder = new Folder("folder"); Document a = new Document("a"); Document b = new Document("b"); folder.addDocuments(a, b); session.save(folder); // change the names of both documents and save one of them a.setName("A"); b.setName("B"); // because `b` is reachable from `a` (via the common shared folder) they will both be persisted, // with PRE_SAVE and POST_SAVE events being fired for each of them session.save(a); ``` -------------------------------- ### Define Domain Entities Source: https://github.com/neo4j/neo4j-ogm/blob/master/README.adoc Use @NodeEntity to map POJOs to graph nodes and @Relationship to define connections between them. ```java @NodeEntity public class Actor { @Id @GeneratedValue private Long id; private String name; @Relationship(type = "ACTS_IN", direction = Relationship.OUTGOING) private Set movies = new HashSet<>(); public Actor() { } public Actor(String name) { this.name = name; } public void actsIn(Movie movie) { movies.add(movie); movie.getActors().add(this); } } @NodeEntity public class Movie { @Id @GeneratedValue private Long id; private String title; private int released; public Movie() { } public Movie(String title, int year) { this.title = title; this.released = year; } } ``` -------------------------------- ### Enable Native Types in Java Configuration Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/nativetypes.adoc Configure Neo4j OGM to use native types by calling the .useNativeTypes() method on the Configuration.Builder in your Java application. ```java Configuration configuration = new Configuration.Builder() .uri("bolt://neo4j:password@localhost") .useNativeTypes() .build() ``` -------------------------------- ### MovieService Interface Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/session.adoc Defines the interface for movie-related operations. ```java public class MovieService { Movie findMovieByTitle(String title) { // implementation } List allMovies() { // implementation } Movie updateTagline(String title, String newTagline) { // implementation } } ``` -------------------------------- ### Maven Dependencies for Neo4j-OGM Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/getting-started.adoc Include these dependencies in your pom.xml to use Neo4j-OGM with the Bolt driver. ```xml org.neo4j neo4j-ogm-core {ogm-version} compile org.neo4j neo4j-ogm-bolt-driver {ogm-version} runtime ``` -------------------------------- ### Chaining Multiple Filters Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/filters.adoc Creates two filters, one for 'manned' and one for 'landed', and chains them together using the 'and' operator to create a composite filter. ```java Filter mannedFilter = new Filter("manned", ComparisonOperator.EQUALS, true); Filter landedFilter = new Filter("landed", ComparisonOperator.EQUALS, false); Filters satelliteFilter = mannedFilter.and(landedFilter); ``` -------------------------------- ### Saving a Collection of Objects Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Illustrates that when saving a collection, separate events are fired for each object within the collection. ```java Document a = new Document("a"); Document b = new Document("b"); // 4 events will be fired when the collection is saved. // - PRE_SAVE a // - PRE_SAVE b // - POST_SAVE a // - POST_SAVE b session.save(Arrays.asList(a, b)); ``` -------------------------------- ### Applying Custom Converter to NodeEntity Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/conversion.adoc Shows how to apply a custom converter to a field within a Neo4j NodeEntity using the @Convert annotation. ```java @NodeEntity public class Person { @Convert(LocationConverter.class) private Location location; ... } ``` -------------------------------- ### Define Movie and Actor Nodes Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Defines simple Node entities for Movie and Actor with a relationship from Movie to Actor. This sets up the structure for cascading saves. ```java @NodeEntity class Movie { String title; Actor topActor; public void setTopActor(Actor actor) { topActor = actor; } } @NodeEntity class Actor { String name; } ``` -------------------------------- ### Set Connection Liveness Check Timeout Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configures the interval in milliseconds to check for stale database connections when using test-on-borrow. This ensures connections are valid before being used. ```java Configuration config = new Configuration.Builder() ... .connectionLivenessCheckTimeout(1000) .build(); ``` -------------------------------- ### Configure Bolt Connection Testing Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Set the interval for testing Bolt connections from the connection pool. A value of 0 tests connections always, while a negative value never tests them. ```properties connection.liveness.interval=0 ``` -------------------------------- ### Load All Entities with Descending Sort Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Loads all entities of a given type, sorted in descending order by a specified field. Requires the Session object and SortOrder class with Direction. ```java Iterable worlds = session.loadAll(World.class, new SortOrder().add(SortOrder.Direction.DESC,"name")) ``` -------------------------------- ### Configure Git Filter for Copyright Header Source: https://github.com/neo4j/neo4j-ogm/wiki/Contribution-Guide These commands configure a Git filter to automatically add the canonical copyright header to files. Use this to ensure all contributions include the required header. ```sh git config filter.ogmheader.smudge 'cat' git config filter.ogmheader.clean '`git rev-parse --git-dir`./Copyright-Header.txt' ``` -------------------------------- ### Multiple Changes, Single Event of Each Type Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Demonstrates that even with multiple modifications to an entity and its relationships, only one PRE_SAVE and one POST_SAVE event are triggered per save operation. ```java // Even though we're making changes to both the folder node, and its relationships, // only one PRE_SAVE and one POST_SAVE event will be fired. folder.removeDocument(a); folder.setName("newFolder"); session.save(folder); ``` -------------------------------- ### Define User, Post, and Group Entities Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Defines entities for User, Post, and Group, illustrating relationships that can be affected by persistence depth. These classes are used to demonstrate how cascading save works with different depths. ```java public class User { private Long id; private String fullName; private List posts; private List groups; } public class Post { private Long id; private String name; private String content; private User author; private List comments; } public class Group { private Long id; private String name; private List members; private Location location; } ``` -------------------------------- ### Set Class Loader Precedence Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configures Neo4j-OGM to use a specific class loader precedence. This is necessary in environments with complex class loading scenarios, such as Spring Boot's @Async or CompletableFuture usage. By default, it uses the current thread's context class loader. ```java Configuration.setClassLoaderPrecedence(Configuration.ClassLoaderPrecedence.OGM_CLASS_LOADER); ``` -------------------------------- ### Enable Native Types in Properties Configuration Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/nativetypes.adoc To use native temporal and spatial types, add the 'use-native-types=true' property to your ogm.properties file. This enables direct mapping without string conversion. ```properties URI=bolt://neo4j:password@localhost use-native-types=true ``` -------------------------------- ### Annotate Node Entity with Properties and Relationships Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Defines an Actor node entity with an ID, mapped properties for name and age, and a relationship to Movie entities. ```java @NodeEntity public class Actor extends DomainObject { @Id @GeneratedValue private Long id; @Property(name="name") private String fullName; @Property("age") // using value attribute to have a shorter definition private int age; @Relationship(type="ACTED_IN", direction=Relationship.Direction.OUTGOING) private List filmography; } @NodeEntity(label="Film") public class Movie { @Id @GeneratedValue Long id; @Property(name="title") private String name; } ``` -------------------------------- ### Maven Dependency for Neo4j-OGM Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/configuration.adoc Add these dependencies to your Maven project to include Neo4j-OGM core and the Bolt driver. ```xml org.neo4j neo4j-ogm-core {ogm-version} org.neo4j neo4j-ogm-bolt-driver {ogm-version} ``` -------------------------------- ### Define Domain Classes for Graph Model Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/tutorial/model.adoc Defines the core domain classes: Movie, Person, Actor, and Reviewer. The Actor and Reviewer classes represent relationship entities, linking Persons to Movies with specific attributes like roles or reviews. ```java class Movie { String title; List actors; List directors; List reviewers; } class Person { String name; } class Actor { List roles; Movie movie; Person person; } class Reviewer { String review; int rating; Movie movie; Person person; } ``` -------------------------------- ### Cypher for Annotated Entity Graph Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Illustrates the Cypher representation of a graph persisted from the annotated Actor and Movie entities. ```cypher (:Actor:DomainObject {name:'Tom Cruise'})-[:ACTED_IN]->(:Film {title:'Mission Impossible'}) ``` -------------------------------- ### Update Actor and Save Movie Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/session.adoc Demonstrates saving a Movie entity after modifying a property on a related, already persisted Actor. The change to the Actor's birth year will be persisted due to cascading. ```java actor.setBirthyear(1956); session.save(movie); ``` -------------------------------- ### EventListener Interface Definition Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/events.adoc Defines the callback methods for handling different types of persistence events. ```java public interface EventListener { void onPreSave(Event event); void onPostSave(Event event); void onPreDelete(Event event); void onPostDelete(Event event); } ``` -------------------------------- ### Bolt Driver TLS Encryption Level Configuration Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/configuration.adoc Configure the encryption level for the Bolt driver using a properties file. Defaults to REQUIRED. ```properties #Encryption level (TLS), optional, defaults to REQUIRED. ``` -------------------------------- ### Composite Type Conversion with CompositeAttributeConverter Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/conversion.adoc Implement CompositeAttributeConverter to map multiple Neo4j properties to a single entity attribute. ```java /** * This class maps latitude and longitude properties onto a Location type that encapsulates both of these attributes. */ public class LocationConverter implements CompositeAttributeConverter { @Override public Map toGraphProperties(Location location) { Map properties = new HashMap<>(); if (location != null) { properties.put("latitude", location.getLatitude()); ``` -------------------------------- ### Runtime Managed Labels with @Labels Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Use the @Labels annotation to dynamically add or remove labels from a node entity at runtime. The backing field should be a List of Strings. ```java @NodeEntity public class Student { @Labels private List labels = new ArrayList<>(); } ``` -------------------------------- ### Define a Simple Relationship Entity Source: https://github.com/neo4j/neo4j-ogm/blob/master/neo4j-ogm-docs/modules/ROOT/partials/reference/annotations.adoc Use @RelationshipEntity to map a POJO to a relationship in Neo4j. Specify the relationship type, and use @StartNode and @EndNode to reference the connected nodes. Ensure the relationship entity is reachable from node entities for persistence. ```java @NodeEntity public class Actor { Long id; @Relationship(type="PLAYED_IN") private Role playedIn; } @RelationshipEntity(type = "PLAYED_IN") public class Role { @Id @GeneratedValue private Long relationshipId; @Property private String title; @StartNode private Actor actor; @EndNode private Movie movie; } @NodeEntity public class Movie { private Long id; private String title; } ``` -------------------------------- ### Setting New Snapshot Version in POMs Source: https://github.com/neo4j/neo4j-ogm/wiki/Release-Checklist This Maven command updates the version in the POM files to a new snapshot version. It's used for sub-module POMs on respective branches. Ensure to replace X.Y.Z with the correct version. ```bash mvn versions:set -DgenerateBackupPoms=false -DnewVersion=X.Y.Z-SNAPSHOT ```