{"id":2968,"date":"2025-05-29T10:36:01","date_gmt":"2025-05-29T10:36:01","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=2968"},"modified":"2025-05-29T10:36:03","modified_gmt":"2025-05-29T10:36:03","slug":"graph-ideas-in-java-with-eclipse-jnosql-half-2","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=2968","title":{"rendered":"Graph Ideas in Java With Eclipse JNoSQL, Half 2"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div>\n<p data-pm-slice=\"1 1 []\">Graph databases have quickly gained recognition in fashionable software program structure, as programs more and more depend on relationships, suggestions, and linked information. From social media platforms and fraud detection programs to suggestion engines and data graphs, graph databases provide a robust strategy to mannequin and traverse complicated relationships which are exhausting to precise effectively in relational databases.<\/p>\n<p>This second a part of the sequence narrows the main focus to Neo4j, the market&#8217;s most distinguished graph database engine. We&#8217;ll discover its structure, question language (Cypher), and see how Java builders can leverage Eclipse JNoSQL 1.1.8 to combine it seamlessly into Java functions.<\/p>\n<h2 data-pm-slice=\"1 1 []\">Understanding Neo4j<\/h2>\n<p data-pm-slice=\"1 3 []\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/dzone.com\/articles\/intro-to-querying-neo4j-using-ogm\">Neo4j<\/a> is a local graph database explicitly constructed to retailer and course of graphs effectively and successfully. It represents information as nodes (vertices) and relationships (edges), which may maintain properties. In contrast to relational databases, the place relationships are inferred by way of international keys, Neo4j treats relationships as first-class residents, leading to quicker and extra expressive graph traversals.<\/p>\n<p>Among the key options that make Neo4j standard embody:<\/p>\n<ul>\n<li>A strong question language: Cypher<\/li>\n<li>ACID-compliant transactional mannequin<\/li>\n<li>Excessive-performance graph traversals<\/li>\n<li>Visible information browser and mature tooling<\/li>\n<li>Robust neighborhood and business assist<\/li>\n<\/ul>\n<h2 data-pm-slice=\"1 1 []\">Meet Cypher: The Graph Question Language<\/h2>\n<p data-pm-slice=\"1 1 []\">Cypher is Neo4j\u2019s declarative question language designed to precise graph patterns intuitively. Its syntax is acquainted to SQL customers however is meant to traverse nodes and relationships, not be a part of tables.<\/p>\n<p>Right here\u2019s a fast comparability:<\/p>\n<div class=\"table-responsive\" style=\"border: none;\">\n<table data-pm-slice=\"3 3 []\" style=\"max-width: 100%; width: auto; table-layout: fixed; display: table;\" width=\"auto\">\n<thead>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<th style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Characteristic<\/th>\n<th style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">SQL<\/th>\n<th style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Cypher<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Entity Retrieval<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">SELECT * FROM E book<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">MATCH (b:E book) RETURN b<\/td>\n<\/tr>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Filtering<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">WHERE title=&#8221;Java&#8221;<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">WHERE b.title=&#8221;Java&#8221;<\/td>\n<\/tr>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Be part of\/Relationship<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">JOIN Book_Category ON&#8230;<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">MATCH (b:E book)-[:is]-&gt;(c:Class) RETURN b<\/td>\n<\/tr>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Grouping &amp; Depend<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">GROUP BY category_id<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">WITH c, rely(b) AS complete<\/td>\n<\/tr>\n<tr style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Schema Flexibility<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Mounted schema<\/td>\n<td style=\"overflow-wrap: break-word; width: auto;\" width=\"auto\">Property graph, extra dynamic<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 data-pm-slice=\"1 1 []\">Getting Began With Neo4j and Eclipse JNoSQL<\/h2>\n<p data-pm-slice=\"1 1 []\"><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/dzone.com\/articles\/eclipse-jnosql-a-quick-overview-with-redis-cassand\">Eclipse JNoSQL<\/a> simplifies database integration by adhering to Jakarta EE specs \u2014 particularly, Jakarta NoSQL and Jakarta Information. On this pattern, we&#8217;ll use Java SE and showcase the way to work together with Neo4j utilizing a website mannequin of books and their classes.<\/p>\n<p>First, guarantee Neo4j is operating. Use Docker to spin it up shortly:<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"docker run --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j\/admin123 neo4j:5.26.3\" data-lang=\"text\/x-sh\">\n<pre><code lang=\"text\/x-sh\">docker run --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j\/admin123 neo4j:5.26.3<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">Now, configure the connection utilizing MicroProfile Config (which helps atmosphere variable overrides):<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"jnosql.neo4j.uri=bolt:\/\/localhost:7687&#10;jnosql.neo4j.username=neo4j&#10;jnosql.neo4j.password=admin123&#10;jnosql.graph.database=neo4j\" data-lang=\"text\/x-properties\">\n<pre><code lang=\"text\/x-properties\">jnosql.neo4j.uri=bolt:\/\/localhost:7687\njnosql.neo4j.username=neo4j\njnosql.neo4j.password=admin123\njnosql.graph.database=neo4j<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">You may overwrite any configuration because of the Twelve Software Issue. For instance, you&#8217;ll be able to replace the manufacturing password with out altering a single line of code. What you must do is about the System atmosphere:<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"export JNOSQL_NEO4J_PASSWORD=PRODUCTION_PASSWORD\" data-lang=\"text\/x-sh\">\n<pre><code lang=\"text\/x-sh\">export JNOSQL_NEO4J_PASSWORD=PRODUCTION_PASSWORD<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<h2 data-pm-slice=\"1 1 []\">Modeling Entities<\/h2>\n<p data-pm-slice=\"1 1 []\">With Neo4j configured and operating, the following step is to outline our area mannequin utilizing <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/dzone.com\/articles\/jakarta-nosql-the-main-idea-behind-the-api\">Jakarta NoSQL<\/a> annotations. On this instance, we deal with two entities \u2014 <code>E book<\/code> and <code>Class<\/code> \u2014 which can type the core nodes in our graph. These lessons will exhibit the way to insert information and outline relationships utilizing Neo4j in a clear, idiomatic manner with Java.<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"@Entity&#10;public class Book {&#10;    @Id&#10;    private String id;&#10;    @Column&#10;    private String name;&#10;}&#10;&#10;@Entity&#10;public class Category {&#10;    @Id&#10;    private String id;&#10;    @Column&#10;    private String name;&#10;}\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">@Entity\npublic class E book {\n    @Id\n    non-public String id;\n    @Column\n    non-public String title;\n}\n\n@Entity\npublic class Class {\n    @Id\n    non-public String id;\n    @Column\n    non-public String title;\n}<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">Eclipse JNoSQL affords a <code>Neo4JTemplate<\/code>, a specialization of <code>Template<\/code>, for native Neo4j entry. This API permits direct interactions with Neo4j utilizing Cypher queries, edge creation, and entity persistence programmatically and expressively.<\/p>\n<p>This is how one can encapsulate persistence logic in a primary service layer:<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"@ApplicationScoped&#10;public class BookService {&#10;    private static final Logger LOGGER = Logger.getLogger(BookService.class.getName());&#10;&#10;    @Inject&#10;    private Neo4JTemplate template;&#10;&#10;    public Book save(Book book) {&#10;        Optional&lt;Book&gt; found = template.select(Book.class).where(&quot;name&quot;).eq(book.getName()).&lt;Book&gt;singleResult();&#10;        return found.orElseGet(() -&gt; template.insert(book));&#10;    }&#10;&#10;    public Category save(Category category) {&#10;        Optional&lt;Category&gt; found = template.select(Category.class).where(&quot;name&quot;).eq(category.getName()).&lt;Category&gt;singleResult();&#10;        return found.orElseGet(() -&gt; template.insert(category));&#10;    }&#10;}\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">@ApplicationScoped\npublic class BookService {\n    non-public static closing Logger LOGGER = Logger.getLogger(BookService.class.getName());\n\n    @Inject\n    non-public Neo4JTemplate template;\n\n    public E book save(E book ebook) {\n        Optionally available<book> discovered = template.choose(E book.class).the place(\"title\").eq(ebook.getName()).<book>singleResult();\n        return discovered.orElseGet(() -&gt; template.insert(ebook));\n    }\n\n    public Class save(Class class) {\n        Optionally available<category> discovered = template.choose(Class.class).the place(\"title\").eq(class.getName()).<category>singleResult();\n        return discovered.orElseGet(() -&gt; template.insert(class));\n    }\n}<\/category><\/category><\/book><\/book><\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">To exhibit a full execution cycle, we use the <code>BookApp<\/code> class, which initializes a CDI container, shops books and classes, creates edges between them, and runs Cypher queries:<\/p>\n<div class=\"codeMirror-wrapper newest\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"public final class BookApp {&#10;    private BookApp() {}&#10;&#10;    public static void main(String[] args) {&#10;        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {&#10;            var template = container.select(Neo4JTemplate.class).get();&#10;            var service = container.select(BookService.class).get();&#10;&#10;            var software = service.save(Category.of(&quot;Software&quot;));&#10;            var java = service.save(Category.of(&quot;Java&quot;));&#10;            var architecture = service.save(Category.of(&quot;Architecture&quot;));&#10;            var performance = service.save(Category.of(&quot;Performance&quot;));&#10;&#10;            var effectiveJava = service.save(Book.of(&quot;Effective Java&quot;));&#10;            var cleanArchitecture = service.save(Book.of(&quot;Clean Architecture&quot;));&#10;            var systemDesign = service.save(Book.of(&quot;System Design Interview&quot;));&#10;            var javaPerformance = service.save(Book.of(&quot;Java Performance&quot;));&#10;&#10;            template.edge(Edge.source(effectiveJava).label(&quot;is&quot;).target(java).property(&quot;relevance&quot;, 10).build());&#10;            template.edge(Edge.source(effectiveJava).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 9).build());&#10;            template.edge(Edge.source(cleanArchitecture).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 8).build());&#10;            template.edge(Edge.source(cleanArchitecture).label(&quot;is&quot;).target(architecture).property(&quot;relevance&quot;, 10).build());&#10;            template.edge(Edge.source(systemDesign).label(&quot;is&quot;).target(architecture).property(&quot;relevance&quot;, 9).build());&#10;            template.edge(Edge.source(systemDesign).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 7).build());&#10;            template.edge(Edge.source(javaPerformance).label(&quot;is&quot;).target(performance).property(&quot;relevance&quot;, 8).build());&#10;            template.edge(Edge.source(javaPerformance).label(&quot;is&quot;).target(java).property(&quot;relevance&quot;, 9).build());&#10;&#10;            System.out.println(&quot;Books in 'Architecture' category:&quot;);&#10;            var architectureBooks = template.cypher(&quot;MATCH (b:Book)-[:is]-&gt;(c:Category {name: 'Architecture'}) RETURN b AS book&quot;, Collections.emptyMap()).toList();&#10;            architectureBooks.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            System.out.println(&quot;Categories with more than one book:&quot;);&#10;            var commonCategories = template.cypher(&quot;MATCH (b:Book)-[:is]-&gt;(c:Category) WITH c, count(b) AS total WHERE total &gt; 1 RETURN c&quot;, Collections.emptyMap()).toList();&#10;            commonCategories.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            var highRelevanceBooks = template.cypher(&quot;MATCH (b:Book)-[r:is]-&gt;(:Category) WHERE r.relevance &gt;= 9 RETURN DISTINCT b&quot;, Collections.emptyMap()).toList();&#10;            System.out.println(&quot; Books with high relevance:&quot;);&#10;            highRelevanceBooks.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            System.out.println(&quot; Books with name: 'Effective Java':&quot;);&#10;            var effectiveJavaBooks = template.cypher(&quot;MATCH (b:Book {name: $name}) RETURN b&quot;, Collections.singletonMap(&quot;name&quot;, &quot;Effective Java&quot;)).toList();&#10;            effectiveJavaBooks.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;        }&#10;    }&#10;}\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">public closing class BookApp {\n    non-public BookApp() {}\n\n    public static void major(String[] args) {\n        strive (SeContainer container = SeContainerInitializer.newInstance().initialize()) {\n            var template = container.choose(Neo4JTemplate.class).get();\n            var service = container.choose(BookService.class).get();\n\n            var software program = service.save(Class.of(\"Software program\"));\n            var java = service.save(Class.of(\"Java\"));\n            var structure = service.save(Class.of(\"Structure\"));\n            var efficiency = service.save(Class.of(\"Efficiency\"));\n\n            var effectiveJava = service.save(E book.of(\"Efficient Java\"));\n            var cleanArchitecture = service.save(E book.of(\"Clear Structure\"));\n            var systemDesign = service.save(E book.of(\"System Design Interview\"));\n            var javaPerformance = service.save(E book.of(\"Java Efficiency\"));\n\n            template.edge(Edge.supply(effectiveJava).label(\"is\").goal(java).property(\"relevance\", 10).construct());\n            template.edge(Edge.supply(effectiveJava).label(\"is\").goal(software program).property(\"relevance\", 9).construct());\n            template.edge(Edge.supply(cleanArchitecture).label(\"is\").goal(software program).property(\"relevance\", 8).construct());\n            template.edge(Edge.supply(cleanArchitecture).label(\"is\").goal(structure).property(\"relevance\", 10).construct());\n            template.edge(Edge.supply(systemDesign).label(\"is\").goal(structure).property(\"relevance\", 9).construct());\n            template.edge(Edge.supply(systemDesign).label(\"is\").goal(software program).property(\"relevance\", 7).construct());\n            template.edge(Edge.supply(javaPerformance).label(\"is\").goal(efficiency).property(\"relevance\", 8).construct());\n            template.edge(Edge.supply(javaPerformance).label(\"is\").goal(java).property(\"relevance\", 9).construct());\n\n            System.out.println(\"Books in 'Structure' class:\");\n            var architectureBooks = template.cypher(\"MATCH (b:E book)-[:is]-&gt;(c:Class {title: 'Structure'}) RETURN b AS ebook\", Collections.emptyMap()).toList();\n            architectureBooks.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            System.out.println(\"Classes with a couple of ebook:\");\n            var commonCategories = template.cypher(\"MATCH (b:E book)-[:is]-&gt;(c:Class) WITH c, rely(b) AS complete WHERE complete &gt; 1 RETURN c\", Collections.emptyMap()).toList();\n            commonCategories.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            var highRelevanceBooks = template.cypher(\"MATCH (b:E book)-[r:is]-&gt;(:Class) WHERE r.relevance &gt;= 9 RETURN DISTINCT b\", Collections.emptyMap()).toList();\n            System.out.println(\" Books with excessive relevance:\");\n            highRelevanceBooks.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            System.out.println(\" Books with title: 'Efficient Java':\");\n            var effectiveJavaBooks = template.cypher(\"MATCH (b:E book {title: $title}) RETURN b\", Collections.singletonMap(\"title\", \"Efficient Java\")).toList();\n            effectiveJavaBooks.forEach(doc -&gt; System.out.println(\" - \" + doc));\n        }\n    }\n}<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">You may as well develop relationships and execute Cypher queries. The instance under reveals the way to outline an edge between two entities utilizing the explicitly <code>Edge<\/code> API offered by Eclipse JNoSQL. This edge represents a relationship with the label <code>is<\/code> and features a property, <code>relevance<\/code> to precise its significance.<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"Edge&lt;Book, Category&gt; edge = Edge.source(book).label(&quot;is&quot;).target(category).property(&quot;relevance&quot;, 9).build();&#10;template.edge(edge);\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">Edge<book category=\"\"> edge = Edge.supply(ebook).label(\"is\").goal(class).property(\"relevance\", 9).construct();\ntemplate.edge(edge);<\/book><\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p>After creating edges, you need to use Cypher to question the graph. For example, the next question retrieves books which have a excessive relevance relationship (&gt;= 9) to any class:<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"var books = template.cypher(&#10;    &quot;MATCH (b:Book)-[r:is]-&gt;(:Category) WHERE r.relevance &gt;= 9 RETURN DISTINCT b&quot;,&#10;    Collections.emptyMap()&#10;).toList();\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">var books = template.cypher(\n    \"MATCH (b:E book)-[r:is]-&gt;(:Class) WHERE r.relevance &gt;= 9 RETURN DISTINCT b\",\n    Collections.emptyMap()\n).toList();<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p>These examples exhibit how Neo4JTemplate can persist and relate area entities and navigate and analyze graph constructions with Cypher.<\/p>\n<p>Check with <code>BookApp<\/code> within the pattern for information setup, insertion, relationship creation, and Cypher queries. After inserting that data into the database, you&#8217;ll be able to test the Ne4J dashboard:<\/p>\n<p><img decoding=\"async\" style=\"width: 638px;\" class=\"fr-fic fr-dib lazyload\" data-image=\"true\" data-new=\"false\" data-sizeformatted=\"57.5 kB\" data-mimetype=\"image\/png\" data-creationdate=\"1748169658228\" data-creationdateformatted=\"05\/25\/2025 10:40 AM\" data-type=\"temp\" data-url=\"https:\/\/dz2cdn1.dzone.com\/storage\/temp\/18426734-graph.png\" data-modificationdate=\"null\" data-size=\"57514\" data-name=\"graph.png\" data-id=\"18426734\" src=\"https:\/\/dz2cdn1.dzone.com\/storage\/temp\/18426734-graph.png\" alt=\"Ne4J dashboard\"\/><\/p>\n<p>You may as well work together with Neo4j utilizing repository interfaces. Eclipse JNoSQL helps <code>Neo4JRepository<\/code> a Jakarta Information extension with Cypher assist:<\/p>\n<div class=\"codeMirror-wrapper\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"&#10;@Repository&#10;public interface BookRepository extends Neo4JRepository&lt;Book, String&gt; {&#10;    Optional&lt;Book&gt; findByName(String name);&#10;&#10;    @Cypher(&quot;MATCH (b:Book)-[:is]-&gt;(c:Category {name: 'Architecture'}) RETURN DISTINCT b&quot;)&#10;    List&lt;Book&gt; findArchitectureBooks();&#10;&#10;    @Cypher(&quot;MATCH (b:Book)-[r:is]-&gt;(:Category) WHERE r.relevance &gt;= 9 RETURN DISTINCT b&quot;)&#10;    List&lt;Book&gt; highRelevanceBooks();&#10;}&#10;&#10;@Repository&#10;public interface CategoryRepository extends Neo4JRepository&lt;Category, String&gt; {&#10;    Optional&lt;Category&gt; findByName(String name);&#10;&#10;    @Cypher(&quot;MATCH (b:Book)-[:is]-&gt;(c:Category) WITH c, count(b) AS total WHERE total &gt; 1 RETURN c&quot;)&#10;    List&lt;Category&gt; commonCategories();&#10;}\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">\n@Repository\npublic interface BookRepository extends Neo4JRepository<book string=\"\"> {\n    Optionally available<book> findByName(String title);\n\n    @Cypher(\"MATCH (b:E book)-[:is]-&gt;(c:Class {title: 'Structure'}) RETURN DISTINCT b\")\n    Record<book> findArchitectureBooks();\n\n    @Cypher(\"MATCH (b:E book)-[r:is]-&gt;(:Class) WHERE r.relevance &gt;= 9 RETURN DISTINCT b\")\n    Record<book> highRelevanceBooks();\n}\n\n@Repository\npublic interface CategoryRepository extends Neo4JRepository<category string=\"\"> {\n    Optionally available<category> findByName(String title);\n\n    @Cypher(\"MATCH (b:E book)-[:is]-&gt;(c:Class) WITH c, rely(b) AS complete WHERE complete &gt; 1 RETURN c\")\n    Record<category> commonCategories();\n}<\/category><\/category><\/category><\/book><\/book><\/book><\/book><\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<p data-pm-slice=\"1 1 []\">The <code>BookApp2<\/code> class demonstrates the way to use these repositories in apply by changing the low-level <code>Neo4JTemplate<\/code>\u00a0utilization with Jakarta Information&#8217;s repository abstraction. This method simplifies the code considerably whereas permitting entry to Cypher&#8217;s expressive energy by way of annotations.<\/p>\n<p>This instance not solely reveals the way to persist entities utilizing commonplace repository strategies like\u00a0<code>findByName<\/code>, but additionally the way to carry out complicated graph queries by way of the <code>@Cypher<\/code> annotation. Moreover, the sting creation continues to be dealt with by way of\u00a0<code>GraphTemplate<\/code>, conserving the connection modeling absolutely express and underneath management.<\/p>\n<p>This dual-model \u2014 repositories for area entry and templates for graph-specific relationships \u2014 affords a terrific steadiness between comfort and adaptability, making it ideally suited for complicated area fashions with wealthy relationships.<\/p>\n<div class=\"codeMirror-wrapper newest\" contenteditable=\"false\">\n<div contenteditable=\"false\">\n<div class=\"codeMirror-code--wrapper\" data-code=\"import jakarta.enterprise.inject.se.SeContainer;&#10;import jakarta.enterprise.inject.se.SeContainerInitializer;&#10;import org.eclipse.jnosql.mapping.graph.Edge;&#10;import org.eclipse.jnosql.mapping.graph.GraphTemplate;&#10;&#10;public final class BookApp2 {&#10;&#10;    private BookApp2() {&#10;    }&#10;&#10;    public static void main(String[] args) {&#10;&#10;        try (SeContainer container = SeContainerInitializer.newInstance().initialize()) {&#10;            var template = container.select(GraphTemplate.class).get();&#10;            var bookRepository = container.select(BookRepository.class).get();&#10;            var repository = container.select(CategoryRepository.class).get();&#10;&#10;            var software = repository.findByName(&quot;Software&quot;).orElseGet(() -&gt; repository.save(Category.of(&quot;Software&quot;)));&#10;            var java = repository.findByName(&quot;Java&quot;).orElseGet(() -&gt; repository.save(Category.of(&quot;Java&quot;)));&#10;            var architecture = repository.findByName(&quot;Architecture&quot;).orElseGet(() -&gt; repository.save(Category.of(&quot;Architecture&quot;)));&#10;            var performance = repository.findByName(&quot;Performance&quot;).orElseGet(() -&gt; repository.save(Category.of(&quot;Performance&quot;)));&#10;&#10;            var effectiveJava = bookRepository.findByName(&quot;Effective Java&quot;).orElseGet(() -&gt; bookRepository.save(Book.of(&quot;Effective Java&quot;)));&#10;            var cleanArchitecture = bookRepository.findByName(&quot;Clean Architecture&quot;).orElseGet(() -&gt; bookRepository.save(Book.of(&quot;Clean Architecture&quot;)));&#10;            var systemDesign = bookRepository.findByName(&quot;System Design Interview&quot;).orElseGet(() -&gt; bookRepository.save(Book.of(&quot;System Design Interview&quot;)));&#10;            var javaPerformance = bookRepository.findByName(&quot;Java Performance&quot;).orElseGet(() -&gt; bookRepository.save(Book.of(&quot;Java Performance&quot;)));&#10;&#10;            template.edge(Edge.source(effectiveJava).label(&quot;is&quot;).target(java).property(&quot;relevance&quot;, 10).build());&#10;            template.edge(Edge.source(effectiveJava).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 9).build());&#10;            template.edge(Edge.source(cleanArchitecture).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 8).build());&#10;            template.edge(Edge.source(cleanArchitecture).label(&quot;is&quot;).target(architecture).property(&quot;relevance&quot;, 10).build());&#10;            template.edge(Edge.source(systemDesign).label(&quot;is&quot;).target(architecture).property(&quot;relevance&quot;, 9).build());&#10;            template.edge(Edge.source(systemDesign).label(&quot;is&quot;).target(software).property(&quot;relevance&quot;, 7).build());&#10;            template.edge(Edge.source(javaPerformance).label(&quot;is&quot;).target(performance).property(&quot;relevance&quot;, 8).build());&#10;            template.edge(Edge.source(javaPerformance).label(&quot;is&quot;).target(java).property(&quot;relevance&quot;, 9).build());&#10;&#10;            System.out.println(&quot;Books in 'Architecture' category:&quot;);&#10;            var architectureBooks = bookRepository.findArchitectureBooks();&#10;            architectureBooks.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            System.out.println(&quot;Categories with more than one book:&quot;);&#10;            var commonCategories = repository.commonCategories();&#10;            commonCategories.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            var highRelevanceBooks = bookRepository.highRelevanceBooks();&#10;&#10;            System.out.println(&quot;Books with high relevance:&quot;);&#10;            highRelevanceBooks.forEach(doc -&gt; System.out.println(&quot; - &quot; + doc));&#10;&#10;            var bookByName = bookRepository.queryByName(&quot;Effective Java&quot;);&#10;            System.out.println(&quot;Book by name: &quot; + bookByName);&#10;        }&#10;    }&#10;}&#10;\" data-lang=\"text\/x-java\">\n<pre><code lang=\"text\/x-java\">import jakarta.enterprise.inject.se.SeContainer;\nimport jakarta.enterprise.inject.se.SeContainerInitializer;\nimport org.eclipse.jnosql.mapping.graph.Edge;\nimport org.eclipse.jnosql.mapping.graph.GraphTemplate;\n\npublic closing class BookApp2 {\n\n    non-public BookApp2() {\n    }\n\n    public static void major(String[] args) {\n\n        strive (SeContainer container = SeContainerInitializer.newInstance().initialize()) {\n            var template = container.choose(GraphTemplate.class).get();\n            var bookRepository = container.choose(BookRepository.class).get();\n            var repository = container.choose(CategoryRepository.class).get();\n\n            var software program = repository.findByName(\"Software program\").orElseGet(() -&gt; repository.save(Class.of(\"Software program\")));\n            var java = repository.findByName(\"Java\").orElseGet(() -&gt; repository.save(Class.of(\"Java\")));\n            var structure = repository.findByName(\"Structure\").orElseGet(() -&gt; repository.save(Class.of(\"Structure\")));\n            var efficiency = repository.findByName(\"Efficiency\").orElseGet(() -&gt; repository.save(Class.of(\"Efficiency\")));\n\n            var effectiveJava = bookRepository.findByName(\"Efficient Java\").orElseGet(() -&gt; bookRepository.save(E book.of(\"Efficient Java\")));\n            var cleanArchitecture = bookRepository.findByName(\"Clear Structure\").orElseGet(() -&gt; bookRepository.save(E book.of(\"Clear Structure\")));\n            var systemDesign = bookRepository.findByName(\"System Design Interview\").orElseGet(() -&gt; bookRepository.save(E book.of(\"System Design Interview\")));\n            var javaPerformance = bookRepository.findByName(\"Java Efficiency\").orElseGet(() -&gt; bookRepository.save(E book.of(\"Java Efficiency\")));\n\n            template.edge(Edge.supply(effectiveJava).label(\"is\").goal(java).property(\"relevance\", 10).construct());\n            template.edge(Edge.supply(effectiveJava).label(\"is\").goal(software program).property(\"relevance\", 9).construct());\n            template.edge(Edge.supply(cleanArchitecture).label(\"is\").goal(software program).property(\"relevance\", 8).construct());\n            template.edge(Edge.supply(cleanArchitecture).label(\"is\").goal(structure).property(\"relevance\", 10).construct());\n            template.edge(Edge.supply(systemDesign).label(\"is\").goal(structure).property(\"relevance\", 9).construct());\n            template.edge(Edge.supply(systemDesign).label(\"is\").goal(software program).property(\"relevance\", 7).construct());\n            template.edge(Edge.supply(javaPerformance).label(\"is\").goal(efficiency).property(\"relevance\", 8).construct());\n            template.edge(Edge.supply(javaPerformance).label(\"is\").goal(java).property(\"relevance\", 9).construct());\n\n            System.out.println(\"Books in 'Structure' class:\");\n            var architectureBooks = bookRepository.findArchitectureBooks();\n            architectureBooks.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            System.out.println(\"Classes with a couple of ebook:\");\n            var commonCategories = repository.commonCategories();\n            commonCategories.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            var highRelevanceBooks = bookRepository.highRelevanceBooks();\n\n            System.out.println(\"Books with excessive relevance:\");\n            highRelevanceBooks.forEach(doc -&gt; System.out.println(\" - \" + doc));\n\n            var bookByName = bookRepository.queryByName(\"Efficient Java\");\n            System.out.println(\"E book by title: \" + bookByName);\n        }\n    }\n}\n<\/code><\/pre>\n<\/p><\/div><\/div>\n<\/div>\n<h2 data-pm-slice=\"1 1 []\">Conclusion<\/h2>\n<p data-pm-slice=\"1 1 []\">Neo4j affords highly effective graph capabilities that Java builders can now entry in a clear, commonplace manner utilizing Eclipse JNoSQL and Jakarta Information. Whether or not you select to work together by way of <code>Neo4JTemplate<\/code> or leverage Jakarta Information repositories. The mixing is easy, type-safe, and expressive. This method helps you to mannequin complicated relationships natively with out sacrificing Java idioms or developer productiveness.<\/p>\n<h2 data-pm-slice=\"1 1 []\">Sources<\/h2>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Graph databases have quickly gained recognition in fashionable software program structure, as programs more and more depend on relationships, suggestions, and linked information. From social media platforms and fraud detection programs to suggestion engines and data graphs, graph databases provide a robust strategy to mannequin and traverse complicated relationships which are exhausting to precise effectively [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2970,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[1893,2859,666,2314,2860,668],"class_list":["post-2968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-concepts","tag-eclipse","tag-graph","tag-java","tag-jnosql","tag-part"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2968"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2968\/revisions"}],"predecessor-version":[{"id":2969,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/2968\/revisions\/2969"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/2970"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-08-05 02:30:18 UTC -->