I have two class first is Company :
@GraphId
private Long graphId;
private String id;
private String name;
Second class is Product :
@GraphId
private Long graphId;
private String id;
private String name;
Between those two class the relationship is company has license for and i want to create relationship entity so I can save the property in the relationship. So i create this relationship entity class called CompanyHasLicenseFor :
@RelationshipEntity(type="company_has_license_for")
public class CompanyHasLicenseFor {
@GraphId
private Long graphId;
private String id;
@StartNode
private Company company;
@EndNode
private Product product;
private Date startDate;
private Date endDate;
}
This is the code i use to create the relationship :
Company company = new Company("Company Test");
companyService.save(company);
Product product = new Product("Product Test");
productService.save(product);
CompanyHasLicenseFor com = new CompanyHasLicenseFor(company, product, new Date(), new Date());
companyHasLicenseForService.save(com);
When i try to create the dummy data using the code above the relationship between two nodes didn't created. Only the node company and product are created. How to create/persist the relationship entity in this case ?
Thank you
Update #1:
I already tried to add CompanyHasLicenseFor as a relationship property in my company class : @GraphId private Long graphId;
private String id;
private String name;
@Relationship(type="company_has_license_for")
private CompanyHasLicenseFor companylicense;
Yet the relationship still not created
Update #2:
@NodeEntity
public class Company {
@GraphId
Long graphId;
String id;
String name;
@Relationship(type="company_has_license_for", direction = "UNDIRECTED")
Set<CompanyHasLicenseFor> companylicenses;
.....
}
@NodeEntity
public class Product {
@GraphId
Long graphId;
String id;
String name;
@Relationship(type = "company_has_license_for", direction = "UNDIRECTED")
Set<CompanyHasLicenseFor> companylicenses;
....
}
@RelationshipEntity(type="company_has_license_for")
public class CompanyHasLicenseFor {
@GraphId
Long graphId;
String id;
@StartNode
Company company;
@EndNode
Product product;
....
}
I'm using Spring Data Neo4j 4.2.0.RELEASE and neo4j-ogm-2.1.1
This is my Sample Code if needed
companyService
,productService
andcompanyHasLicenseForService
are all Spring DataRepository
s? If so it should all work. You will probably need a@Transactional
surrounding your three save methods if you want that action to be atomic. – digx1