2
votes

Hoping my team is doing something silly here, but, using SDN 3.3 against Neo4j 2.1.6, I'm getting a PersistentEntityConversionException when trying to fetch a particular entity.

The data model goes something like this:

  • Have a base node entity model, call it A. It's abstract in SDN (it actually descends from a couple other classes, but the root is @NodeEntity).
  • Have two sibling entities, each of which descends from A. Call these B and C.

I'm executing a Cypher query that effectively looks for nodes with the label from A (which should include B and C). The Java code looks a bit like this:

List<A> nodeList = this.repo.getNodes();

I get the query back, and then iterate through the results and, using a template, "fetch" the results. Eventually, I get this exception:

org.springframework.data.neo4j.mapping.PersistentEntityConversionException: Requested a entity of type 'class B', but the entity is of type 'class C'.

This method of fetching used to work in SDN 3.2.1.

Any assistance would be greatly appreciated.

Thanks in advance!

2

2 Answers

1
votes

After some more digging, I found the cause of my issues, and I'll admit I feel like a bit of a dope.

In reality, the models in the domain are a bit more complex (and a bit deeper) than what I'd posted. For me, the issue boiled down to needing to set enforceTargetTypeto true and to also set the elementClassto the targeted type.

In other words, my A class had a relationship with yet another model (call it M), and that relationship wasn't properly annotated.

I ended up tracing through a good bit of the SDN code and found that it was only when I was trying to build that relationship with the associated M class that things were getting confused.

Still, Leward's answer above may help some others in similar cases.

0
votes

I had the same issue this and looks like a bug in Spring Data Neo4j.

I found a workaround to make it work: disable the type safety checking in Spring Data Neo4j.

In your Spring XML context, simply add:

<bean id="typeSafetyPolicy" class="org.springframework.data.neo4j.support.typesafety.TypeSafetyPolicy">
    <constructor-arg value="NONE" />
</bean>

Keep in mind that this can create undesired side effects. See the documentation: http://docs.spring.io/spring-data/data-neo4j/docs/3.3.0.RELEASE/reference/html/#entity_type_safety