Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-11-2020 02:55 AM
Hi this is my Receipt entity which contains Unit object with the following properties. My problem is that I dont want to create duplicate Unit nodes each time new Receipt is created instead just connect this Receipt to the already stored Unit with same properties.
Now I am using default save method inherited from Neo4jRepository class, but I would like to create query to accomplish that requirement I described above. Thanks.
@NodeEntity
public class Receipt {
@Id
@GeneratedValue
private Long id;
private Long ownerID;
private String friendlyName;
private String shop;
private String createdDateTime;
@Relationship("CONTAINS")
private ArrayList<Item> items;
@Relationship("ISSUED_AT")
private Unit unit;
private Double totalPrice;
@NodeEntity
public class Unit {
@Id
@GeneratedValue
private Long id;
private String buildingNumber;
private String municipality;
private String postalCode;
private String country;
private String street;
Solved! Go to Solution.
08-11-2020 08:38 AM
The easiest way I can think of is to create custom search query (see https://neo4j.com/developer/spring-data-neo4j/, section "Repository for Queries") that will return existing Unit id if unit does exists or null in other case; each time you save receipt you have to check if Unit exists, and if it does pass reference to the Unit into the Receipt.
08-11-2020 08:38 AM
The easiest way I can think of is to create custom search query (see https://neo4j.com/developer/spring-data-neo4j/, section "Repository for Queries") that will return existing Unit id if unit does exists or null in other case; each time you save receipt you have to check if Unit exists, and if it does pass reference to the Unit into the Receipt.
08-11-2020 09:29 AM
Thanks for quick response.
All the sessions of the conference are now available online