<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Neo4J &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/neo4j/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 16:38:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Neo4J &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Neo4j: WHERE Clause vs Curly Braces in MATCH Clause</title>
		<link>https://myshittycode.com/2015/08/20/neo4j-where-clause-vs-curly-braces-in-match-clause/</link>
					<comments>https://myshittycode.com/2015/08/20/neo4j-where-clause-vs-curly-braces-in-match-clause/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 20 Aug 2015 18:39:43 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Cypher Query Language]]></category>
		<category><![CDATA[Neo4J]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=821</guid>

					<description><![CDATA[<p>PROBLEM With Cypher Query Language, you can write similar queries that yield the same result. For example:- &#8230; AND &#8230; &#8230; returns the same result. So, which one is better in terms of performance? SOLUTION Neo4j provides a very helpful command called EXPLAIN that allows us to do some investigation ourselves. The EXPLAIN command displays [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/20/neo4j-where-clause-vs-curly-braces-in-match-clause/">Neo4j: WHERE Clause vs Curly Braces in MATCH Clause</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>With Cypher Query Language, you can write similar queries that yield the same result.</p>



<p>For example:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(b:Beverage)
WHERE b.name = &#039;Dark Roast&#039;
RETURN p.name as PERSON
</pre></div>


<p>&#8230; AND &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(b:Beverage{name:&#039;Dark Roast&#039;})
RETURN p.name as PERSON
</pre></div>


<p>&#8230; returns the same result.</p>



<p>So, which one is better in terms of performance?</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>Neo4j provides a very helpful command called <code>EXPLAIN</code> that allows us to do some investigation ourselves.</p>



<p>The <code>EXPLAIN</code> command displays the query plan without actually executing the query.</p>



<p>To use it, just add <code>EXPLAIN</code> in front of the query.</p>



<p>In this example, both queries produce exactly the same query plan.</p>



<figure class="wp-block-image aligncenter"><img fetchpriority="high" decoding="async" width="188" height="570" src="https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-1-29-07-pm-1.png?x45560" alt="" class="wp-image-822" srcset="https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-1-29-07-pm-1.png 188w, https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-1-29-07-pm-1-99x300.png 99w" sizes="(max-width: 188px) 100vw, 188px" /></figure>



<p>In another word, while both queries look slightly different, they perform exactly the same.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/20/neo4j-where-clause-vs-curly-braces-in-match-clause/">Neo4j: WHERE Clause vs Curly Braces in MATCH Clause</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2015/08/20/neo4j-where-clause-vs-curly-braces-in-match-clause/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">821</post-id>	</item>
		<item>
		<title>Neo4j: Playing with Cypher Query Language</title>
		<link>https://myshittycode.com/2015/08/20/neo4j-playing-with-cypher-query-language/</link>
					<comments>https://myshittycode.com/2015/08/20/neo4j-playing-with-cypher-query-language/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 20 Aug 2015 16:08:05 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Cypher Query Language]]></category>
		<category><![CDATA[Neo4J]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=808</guid>

					<description><![CDATA[<p>PROBLEM Every week, my shitty coworkers struggle to reach consensus on where to go for lunches and what beverages to order in the morning. SOLUTION To further understand the phenomenon of this first world problem, here&#8217;s a shitty graph database powered by Neo4j to visualize the love/hate relationship between my shitty coworkers and the shitty [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/20/neo4j-playing-with-cypher-query-language/">Neo4j: Playing with Cypher Query Language</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>Every week, my shitty coworkers struggle to reach consensus on where to go for lunches and what beverages to order in the morning.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<p>To further understand the phenomenon of this first world problem, here&#8217;s a shitty graph database powered by Neo4j to visualize the love/hate relationship between my shitty coworkers and the shitty restaurants/beverages.</p>



<figure class="wp-block-image aligncenter"><img decoding="async" width="578" height="459" src="https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-11-19-46-am-1.png?x45560" alt="" class="wp-image-819" srcset="https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-11-19-46-am-1.png 578w, https://myshittycode.com/wp-content/uploads/2015/08/screen-shot-2015-08-20-at-11-19-46-am-1-300x238.png 300w" sizes="(max-width: 578px) 100vw, 578px" /></figure>



<p>Now, let&#8217;s flex the power of Cypher Query Language to unclutter this shitty mess.</p>



<h3 class="wp-block-heading">People who love Whistle Binkies</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(:Restaurant{name:&#039;Whistle Binkies&#039;})
RETURN p.name as PERSON
</pre></div>


<p>&#8230; OR &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(r:Restaurant)
WHERE r.name = &#039;Whistle Binkies&#039;
RETURN p.name as PERSON
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
PERSON
Mike
Corey
Jason
</pre></div>


<h3 class="wp-block-heading">Restaurants with at least 2 people loving it</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (:Person)-&#x5B;:loves]-&gt;(r:Restaurant)
WITH r, count(*) as tr
WHERE tr &gt; 2
RETURN r.name as RESTAURANT, tr as TOTAL
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
RESTAURANT         TOTAL
Whistle Binkies    3
Newts              5
John Hardy&#039;s       3
Noodles and Co     4
</pre></div>


<h3 class="wp-block-heading">Restaurants that everyone loves</h3>



<p>Winner winner chicken dinner!</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)
WITH distinct count(*) as tp
MATCH (p)-&#x5B;:loves]-&gt;(r:Restaurant)
WITH tp, r, count(*) as tr
WHERE tr = tp
RETURN r.name as RESTAURANT
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
RESTAURANT
Newts
</pre></div>


<h3 class="wp-block-heading">Beverages that only one person loves&#8230; and find out who that weirdo is</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(b1:Beverage)
WITH b1, count(*) as tb
WHERE tb = 1
MATCH (p)-&#x5B;:loves]-&gt;(b2:Beverage)
WHERE b1.name = b2.name
RETURN p.name as PERSON, b1.name as BEVERAGE
</pre></div>


<p>&#8230; OR &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(b:Beverage)
WITH b, count(*) as tb
WHERE tb = 1
MATCH (p)-&#x5B;:loves]-&gt;(:Beverage{name:b.name})
RETURN p.name as PERSON, b.name as BEVERAGE
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
PERSON    BEVERAGE
Cory      Fufu Drink
Corey     Vanilla Latte
</pre></div>


<h3 class="wp-block-heading">People who love to eat at John Hardies and drink Cold Press&#8230; ie: people with high taste</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (b:Beverage)&lt;-&#x5B;:loves]-(p:Person)-&#x5B;:loves]-&gt;(r:Restaurant)
WHERE r.name = &quot;John Hardy&#039;s&quot; and b.name = &#039;Cold Press&#039;
RETURN p.name as PERSON
</pre></div>


<p>&#8230; OR &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (b:Beverage{name:&#039;Cold Press&#039;})&lt;-&#x5B;:loves]-(p:Person)-&#x5B;:loves]-&gt;(r:Restaurant{name:&quot;John Hardy&#039;s&quot;})
RETURN p.name as PERSON
</pre></div>


<p>&#8230; OR &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(r:Restaurant{name:&quot;John Hardy&#039;s&quot;}),
      (p)-&#x5B;:loves]-&gt;(b:Beverage{name:&#039;Cold Press&#039;})
RETURN p.name as PERSON
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
PERSON
Mike
Jason
</pre></div>


<h3 class="wp-block-heading">People who love and hate the same beverage</h3>



<p>&#8220;When love and hate collide&#8221; &#8211; Def Leppard&#8230; ie: coworkers with identity crisis.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (b:Beverage)&lt;-&#x5B;:loves]-(p:Person)-&#x5B;:hates]-&gt;(:Beverage{name:b.name})
RETURN p.name as PERSON, b.name as BEVERAGE
</pre></div>


<p>&#8230; OR &#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: sql; title: ; notranslate">
MATCH (p:Person)-&#x5B;:loves]-&gt;(b:Beverage),
      (p)-&#x5B;:hates]-&gt;(:Beverage{name:b.name})
RETURN p.name as PERSON, b.name as BEVERAGE
</pre></div>


<p>Result:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
PERSON    BEVERAGE
Corey     Dark Roast
</pre></div>


<h2 class="wp-block-heading">LESSON LEARNED</h2>



<p>While Cypher Query Language syntax looks much different than SQL syntax, they are pretty easy to learn and understand.</p>



<p>Cypher Query Language doesn&#8217;t and will not solve people problem though. We still argue about lunches/beverages every week and those who are willing to drive usually win the arguments.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/20/neo4j-playing-with-cypher-query-language/">Neo4j: Playing with Cypher Query Language</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2015/08/20/neo4j-playing-with-cypher-query-language/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">808</post-id>	</item>
		<item>
		<title>Spring Data Neo4J: Requested a entity of type &#8216;X&#8217;, but the entity is of type &#8216;Y&#8217;</title>
		<link>https://myshittycode.com/2015/08/19/spring-data-neo4j-requested-a-entity-of-type-x-but-the-entity-is-of-type-y/</link>
					<comments>https://myshittycode.com/2015/08/19/spring-data-neo4j-requested-a-entity-of-type-x-but-the-entity-is-of-type-y/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Wed, 19 Aug 2015 20:53:49 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Neo4J]]></category>
		<category><![CDATA[Spring Data Neo4J]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=805</guid>

					<description><![CDATA[<p>PROBLEM Let&#8217;s assume we have a node entity like this:- When saving this entity, we get this exception:- SOLUTION This problem occurs because relationship likes is being used by both Restaurant entity and Beverage entity. To fix it, we need to enforce the target type.</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/19/spring-data-neo4j-requested-a-entity-of-type-x-but-the-entity-is-of-type-y/">Spring Data Neo4J: Requested a entity of type &#8216;X&#8217;, but the entity is of type &#8216;Y&#8217;</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>Let&#8217;s assume we have a node entity like this:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
@NodeEntity
public final class Person {
    @GraphId
    private Long id;

    private String name;

    @Fetch
    @RelatedTo(type = &quot;likes&quot;, direction = OUTGOING)
    public Set&lt;Restaurant&gt; likesRestaurants;

    @Fetch
    @RelatedTo(type = &quot;likes&quot;, direction = OUTGOING)
    public Set&lt;Beverage&gt; likesBeverages;

    public Person() {
    }

    public Person(final String name,
                  final Set&lt;Restaurant&gt; likesRestaurants,
                  final Set&lt;Beverage&gt; likesBeverages) {
        this.name = name;
        this.likesRestaurants = likesRestaurants;
        this.likesBeverages = likesBeverages;
    }
}
</pre></div>


<p>When saving this entity, we get this exception:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Exception in thread &quot;main&quot; org.springframework.data.neo4j.mapping.PersistentEntityConversionException:
Requested a entity of type &#039;class myproject.Restaurant&#039;,
but the entity is of type &#039;class myproject.Beverage&#039;.
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>This problem occurs because relationship <code>likes</code> is being used by both <code>Restaurant</code> entity and <code>Beverage</code> entity.</p>



<p>To fix it, we need to enforce the target type.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; highlight: [9,13]; title: ; notranslate">
@NodeEntity
public final class Person {
    @GraphId
    private Long id;

    private String name;

    @Fetch
    @RelatedTo(type = &quot;likes&quot;, direction = OUTGOING, enforceTargetType = true)
    public Set&lt;Restaurant&gt; likesRestaurants;

    @Fetch
    @RelatedTo(type = &quot;likes&quot;, direction = OUTGOING, enforceTargetType = true)
    public Set&lt;Beverage&gt; likesBeverages;

    public Person() {
    }

    public Person(final String name,
                  final Set&lt;Restaurant&gt; likesRestaurants,
                  final Set&lt;Beverage&gt; likesBeverages) {
        this.name = name;
        this.likesRestaurants = likesRestaurants;
        this.likesBeverages = likesBeverages;
    }
}
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2015/08/19/spring-data-neo4j-requested-a-entity-of-type-x-but-the-entity-is-of-type-y/">Spring Data Neo4J: Requested a entity of type &#8216;X&#8217;, but the entity is of type &#8216;Y&#8217;</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2015/08/19/spring-data-neo4j-requested-a-entity-of-type-x-but-the-entity-is-of-type-y/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">805</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 52/73 queries in 0.024 seconds using Disk

Served from: myshittycode.com @ 2026-02-18 15:25:42 by W3 Total Cache
-->