<?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>Spring Data Neo4J &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/spring-data-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.3</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Spring Data 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>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 3/67 queries in 0.171 seconds using Disk

Served from: myshittycode.com @ 2026-03-11 08:16:21 by W3 Total Cache
-->