I am trying to save a node into Neo4j database with Spring boot and getting the following Exception:
java.lang.IllegalArgumentException: Class class com.test.neo4j.model.Company is not a valid entity class. Please check the entity mapping.
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:77) ~[neo4j-ogm-core-3.2.11.jar:3.2.11]
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:51) ~[neo4j-ogm-core-3.2.11.jar:3.2.11]
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:480) ~[neo4j-ogm-core-3.2.11.jar:3.2.11]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
Below is my Entity class:
package com.test.neo4j.model;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;
@NodeEntity
public class Company {
@Id
private String id;
private String name;
public Company() {}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Below is my repository:
package com.test.neo4j.repository;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import com.test.neo4j.model.Company;
public interface CompanyRepository extends Neo4jRepository<Company, String>{
}
I am Autowiring
the repo in my service and calling save
with it. Now, I have looked up the other answers and made sure of the following:
- Package name does not contain any upper case character
- Model class has got default constructor
id
is explicitly set in the service
Am I missing anything else here?
Company
entity does not get scanned. Have you explicitly defined the scan path or put the entity class in a package with different (starting) name than your Spring Boot configuration / application class? – meistermeier