cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Missing @TargetNode declaration when migrating to neo4j 4.1.3 enterprise and SDN/RX driver

We recently working on migrating a project from using neo4j bolt driver to neo4j SDN/RX driver. Testing was done on spring boot 2.4.0 and spring-data-neo4j 6.0.1. The following error was noticed :
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shelfService' defined in URL [jar:file:/Users/rbaiad/IdeaProjects/smartcapacity-import/target/smartcapacity-import-0.0.1-RELEASE.jar!/BOOT-INF/classes!/com/ciena/scimport/service/ShelfService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tapiTopologyNodeRepository' defined in com.ciena.tapimongo.repository.TapiTopologyNodeRepository defined in @EnableNeo4jRepositories declared on ScUpdaterApplication: Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'neo4jTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'neo4jTemplate' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.data.mapping.MappingException: Missing @TargetNode declaration in class com.ciena.smartcapacity.domain.Connects
Although looking into Connects class we see that the @TargetNode is indeed declared :

@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude = {"route", "ne"}, callSuper = false)
@ToString(exclude = {"route", "ne"})
@RelationshipProperties
public class Connects {
  @Id
  @GeneratedValue
  private Long graphId;
  @Property(name = "Route_ID")
  private String id;
  @Property("Capture_Id")
  private Long captureId;
  @Property(name = "Date_NetworkExtract")
  @DateLong
  private Date networkExtract;
  private RouteEntity route;
  @TargetNode
  private NetworkElement ne;
}

And the following snippets shows the relationship :

@Relationship(type = "CONNECTS", direction = Relationship.Direction.INCOMING)
private List<Connects> incomingConnections = new ArrayList<>();
5 REPLIES 5

A @RelationshipProperties class must not have an @Id field.
Also the RouteEntity route definition is obsolete. I assume that this is the entity where you define the relationship in, right?

After getting rid of the Id field in the relationships , we still see the same issue of missing with one of the relationships,

Missing @TargetNode declaration in class com.ciena.smartcapacity.domain.Connects

The @targetNode for that relationship is
Networkelement that is is extending Entity as following


@Data
@NoArgsConstructor
@JsonIdentityInfo(generator= ObjectIdGenerators.PropertyGenerator.class, property="id")
@EqualsAndHashCode(exclude = {"routes", "incomingConnections"}, callSuper = false)

@Node("Ne")
public class NetworkElement extends Entity {
    @Property(name = "Entity_Physshelf")
    private String shelf;
...etc...
    @Relationship(type = "CONNECTS", direction = Relationship.Direction.INCOMING)
    private List<Connects> incomingConnections = new ArrayList<>();

As for the route entity it is our domain object that defines the relationship

@Node("Route")
public class RouteEntity {
    @Id
    @GeneratedValue
    private Long graphId;

    @Property(name = "Route_ID")
    private String id;

    @Relationship(type = "CARRIED_BY", direction = Relationship.Direction.OUTGOING)
    private List<CarriedBy> routesCarriedBy = new ArrayList<>();;

    @Relationship(type = "CARRIED_BY", direction = Relationship.Direction.INCOMING)
    private List<CarriedBy> routesCarrying = new ArrayList<>();

    @Relationship(type = "CONNECTS", direction = Relationship.Direction.OUTGOING)
    private List<Connects> nesConnectingTo = new ArrayList<>();
.....etc

We have te same issue (missing TargetNode). How did you finally solve it?
I'll try putting it on all concrete classes, but that shouldn't be necessary. Looks more like a bug or oversight.

I'm also wondering if there's an answer to this. We've recently run into the issue (missing TargetNode) on sub-classes that extend a super-class with the @TargetNode annotation.

There will be a fix in the upcoming versions starting with 6.1.6 for this. Fix flaky RelationshipProperties parsing in cyclic scenarios. · Issue #2398 · spring-projects/spring...
The problem was a non-deterministic property discovery when using inheritance for relationship properties combined with a reference / references that lead again to the very same relationship property.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online