Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-10-2022 10:56 PM
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.
03-11-2022 12:17 AM
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
03-11-2022 01:16 AM
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>
03-11-2022 02:02 AM
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.
03-11-2022 02:07 AM
I see.I will use the starter in my project.Thanks a lot😄
03-11-2022 11:21 PM
Sorry to bother you again
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?
03-12-2022 11:19 AM
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.
03-16-2022 01:48 AM
Thank you for your help
All the sessions of the conference are now available online