Required identifier property not found for class com.example.demo.entity.Concept!

In my Spring Boot (Version:2.6.4) Project,I use Neo4j-OGM to get information from graph database.But I encounter a problem.
The error message is
"Required identifier property not found for class com.example.demo.entity.Concept!"

Below are some files.
1、pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-core</artifactId>
    <version>3.2.30</version>
</dependency>

2、Concept.java

package com.example.demo.entity;
import lombok.Data;
import org.neo4j.ogm.annotation.*;

import java.util.HashSet;
import java.util.Set;

@Data
@NodeEntity(label = "Concept")
public class Concept {
    @Id
    @GeneratedValue
    private Long id;
    String entity_id;
    String entity_name;
    @Relationship(type = "Include")
    Set<Include> sets = new HashSet<>();
}

3、Include.java

package com.example.demo.entity;

import lombok.Data;
import org.neo4j.ogm.annotation.*;

@Data
@RelationshipEntity(type = "Include")
public class Include {
    @Id
    @GeneratedValue
    private Long id;
    String note;
    String relation_id;
    String relation_name;
    @StartNode
    Concept start;
    @EndNode
    Concept end;
}

4、ConceptRepository.java

package com.example.demo.repository;

import com.example.demo.entity.Concept;
import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface ConceptRepository extends Neo4jRepository<Concept,Long> {
}

5、neo4jController.java

package com.example.demo.controller;

import com.example.demo.entity.Concept;
import com.example.demo.entity.Include;
import com.example.demo.repository.ConceptRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
public class neo4jController {
    @Autowired
    ConceptRepository cRepo;

    @GetMapping("/find")
    public void findNodes() {
        Iterable<Concept> parentNodes = cRepo.findAll();
        for (Concept parentNode : parentNodes) {
            Set<Include> relationNodeSet = parentNode.getSets();
            for (Include relationNode : relationNodeSet) {
                System.out.println("id:" + parentNode.getId() + "startNode:" + parentNode.getEntity_name() + " relation:" + relationNode.getRelation_name() + "endNode:" + relationNode.getEnd().getEntity_name());
            }
        }
    }
}

6、Neo4jConfig.java

package com.example.demo.config;

import org.neo4j.driver.Driver;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableNeo4jRepositories(basePackages = "com.example.demo.repository")
@EntityScan(basePackages = {"com.example.demo.entity.Concept","com.example.demo.entity.Include"})
@EnableTransactionManagement
public class Neo4jConfig {
    @Value("${spring.neo4j.uri}")
    private String uri;
    @Value("${spring.neo4j.authentication.username}")
    private String userName;
    @Value("${spring.neo4j.authentication.password}")
    private String password;

    @Bean
    public org.neo4j.ogm.config.Configuration getConfiguration() {
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder().uri(uri).connectionPoolSize(100).credentials(userName, password).withBasePackages("com.xm").build();
        return configuration;
    }

    @Bean
    public SessionFactory sessionFactory() {
        return new SessionFactory(getConfiguration(),"com.example.demo.entity");
    }

    @Bean("neo4jTransaction")
    public Neo4jTransactionManager neo4jTransactionManager(SessionFactory sessionFactory) {
        return new Neo4jTransactionManager((Driver) sessionFactory);
    }
}

:arrow_down: :arrow_down: :arrow_down:
One solution I saw before is replacing all the Neo4j-OGM annotations with import org.springframework.data.neo4j.core.schema.*
But after I replaced them,I couln't find annotations like @ NodeEntity,@ StartNode,@ EndNode,etc

So what can I do to solve the problem. :sob:Thank u.

Your problem is rooted in mixing the newest Spring Data Neo4j that does not depend anymore on Neo4j-OGM with Neo4j-OGM. You get this version because you are referring to the starter:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

Spring Data Neo4j starting with version 6 brings its own annotations like @Node with it.
The best option is to go full in Spring Data Neo4j, the migration guide is here: Spring Data Neo4j

Thank you for your reply.
Sorry for having another question.Is there any difference between the following two methods when I develop a Spring Boot project?
1、

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>

2、

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
</dependency>

The advantage of using the starter is that you get the predefined version of Spring Data Neo4j meant to work with Spring Boot in this very version. Of course you can also use other versions but this is the version, Spring Boot was tested with.
As long as Spring Data Neo4j (starter or explicitly defined) is on the classpath you get all the autoconfiguration support from the starter. This means that in the best case you do not have to specify any bean manually (Neo4jClient, Neo4jTemplate...)
I would always advice to use the starter because it keeps Spring Data Neo4j up to date when updating Spring Boot.

I see.I will use the starter in my project.Thanks a lot😄

Sorry to bother you again :rofl:

At the top of the Neo4j Java Driver Spring Boot Starter - Developer Guides, there is a note says The Spring Boot starter is now superseded by the Neo4j Java Driver auto config starting with Spring Boot 2.4. For Spring Boot 2.3. we will still provide support with this starter.
Does it mean starting with Spring Boot 2.4.,Neo4j officially recommends us to use the Neo4j Java Driver rather than the starter?

The starter always included the driver. The same like Boot does from 2.4.
The starter also included auto configuration. This is included in Boot from 2.4 onwards.

Thank you for your help :smiley:

Hello,I'm sorry to bother you,I encountered a problem with Neo4j dependencies, and the following is the error message:Required identifier property not found for class com.wyh.csustrecovery.demos.Domain.distance!

  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-neo4j</artifactId>
            <version>2.6.13</version> <!-- 根据您的需求选择合适的版本号 -->
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-ogm-core</artifactId>
            <version>3.2.24</version>
        </dependency>

2.Here are the classes

package com.wyh.csustrecovery.demos.Domain;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.neo4j.ogm.annotation.*;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
@RelationshipEntity(type = "distance")
public class distance implements Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @StartNode
    private Place startLocate;

    @EndNode
    private Place endLocate;
    
    @Property(name = "distance")
    private String distanceType; //RelationType(较远,较近,附近)
    
    @Property(name = "value")
    private Double value; //distance value


}

package com.wyh.csustrecovery.demos.Domain;

import lombok.Builder;
import lombok.Data;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;

import java.io.Serializable;

@Data
@Builder
@NodeEntity("Place")
public class Place implements Serializable {
    @Id
    @GeneratedValue
    private Long id;

    @Property("name")
    private String name;

    @Property("lng")
    private Double lng;

    @Property("lat")
    private Double lat;

    @Property("alias")
    private  String alias;

}

3.Here are the interfaces

package com.wyh.csustrecovery.demos.Repository;

import com.wyh.csustrecovery.demos.Domain.Place;
import com.wyh.csustrecovery.demos.Domain.distance;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 关系接口
 */
@Repository
public interface DistanceRepository extends Neo4jRepository<distance, Long> {

    @Query("match p= ((a)-[r]->(b) )  WHERE id(a) = $0 return b limit 200")
    List<Place> find_End_By_FirstNode(Long id);

    @Query("MATCH (a)-[r]->() WHERE id(a) = $0 RETURN r")
    List<distance> find_Relations_By_Node(Long id);

    @Query("MATCH (a)-[r]->(b) WHERE id(a) = $0 RETURN r")
    distance find_Relation_By_Id(Long id);

    @Query("MATCH (n:distance) RETURN n")
    List<distance> find_All_Distances();

    @Query("MATCH (a:Place {name: &0})-[r]->(b:Place {name: &1}) RETURN r")
    distance find_distance_EndTOFirstBy_Name(String startName,String endName);

    @Query("MATCH (a:Place {id: &0})-[r]->(b:Place {id: &1}) RETURN r")
    distance find_distance_EndTOFirstBy_Id(Long begin_id,Long end_id);

   @Query("MATCH (a:Place)-[r]->(b:Place) \n" +
           "WHERE a.name CONTAINS &0 AND b.name CONTAINS &1\n" +
           "RETURN r\n")
    List<distance> getDistances(String contains_beginName,String contains_endName);
}

SDN is the only dependency you need to use it. Try removing the OGM dependency.

I don’t recall StartNode and EndNode annotations in SDN.

https://docs.spring.io/spring-data/neo4j/reference/object-mapping/metadata-based-mapping.html
You may want to read this reference on custom queries.

https://docs.spring.io/spring-data/neo4j/reference/appendix/custom-queries.html