Reputation: 1070
I am working on a Spring Boot application that uses Neo4j for data storage,
I have a relationship of SkillCategory
and Skills
.
So one SKillCategory
contains many skills.
Below is the Domain structure:
Skill.java
@NodeEntity
public class Skill extends BaseEntity {
private String name;
private boolean isVerified;
private boolean isEnabled = true;
@Relationship(type = SKILL_OF_LEVEL, direction = "OUTGOING")
private SkillLevel skillLevel;
public Skill() {
}
public Skill(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean enabled) {
isEnabled = enabled;
}
public boolean isVerified() {
return isVerified;
}
public void setVerified(boolean verified) {
isVerified = verified;
}
public SkillLevel getSkillLevel() {
return skillLevel;
}
public void setSkillLevel(SkillLevel skillLevel) {
this.skillLevel = skillLevel;
}
}
SkillCategory.java
@NodeEntity
public class SkillCategory extends BaseEntity {
private String name;
private boolean isEnabled = true;
@Relationship(type = CONTAINS_SKILL,direction = "OUTGOING")
private List<Skill> skillList;
public SkillCategory() {
}
public SkillCategory(String name) {
this.name = name;
}
public SkillCategory(String name, List<Skill> skillList) {
this.name = name;
this.skillList = skillList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEnabled() {
return isEnabled;
}
public void setEnabled(boolean enabled) {
isEnabled = enabled;
}
public List<Skill> getSkillList() {
return skillList;
}
public void setSkillList(List<Skill> skillList) {
this.skillList = skillList;
}
}
I am using GraphRepository
to perform CRUD operations.
I am creating SkillCategory
& Skills
on application boot.
Here is the problem: if I delete the DB & start Spring Boot, everything works fine.
But when I restart the Spring Boot application, skillList
in SkillCategory
is null.
If anyone have experience in Spring Data Neo4j, kindly help me narrow down the issue.
Repository Code :
@Repository
public interface SkillGraphRepository extends GraphRepository<Skill>{
List<SkillCategory> findAll();
}
I assume that if i fetch skillCategory it'll automatically eager load to fetch skills in SkillCategory also
I am simply using a Service that injects SkillCategoryRepository
skillCategoryService.create(new skillCategory("Category1"),Arrays.asList(new Skill("Skill 1"),new SKill("Skill 2")));
Upvotes: 0
Views: 124
Reputation: 1088
The data disappearance between start ups was caused by starting SDN with the embedded driver and an impermanent data store.
When setting the driver to: driver=org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
you must also make sure you set a location for the Neo4j datastore URI=file:///var/tmp/neo4j.db
to make data persistable between start ups otherwise your data will only exist while the application is running.
More details can be found here.
Upvotes: 2