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);
}
}
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. Thank u.