CdVr
CdVr

Reputation: 313

spring data neo4j 6.1.1 Repository Relationship primary_id not allowing to use UUID String where as for Node Primary_id UUID String is working

I have the following relationship entity for neo4j Graph Model using Spring data neo4j 6.1.1 to represent relationship like Person-BookedFor->Movie where i can use UUID string for node repositories (Person, Movie) but not for the following relationship Entity BookedFor.

Note: since the neo4j doc describes this neo4j doc ref

public interface BookedForRepository extends Neo4jRepository<BookedFor, String> {}

@RelationshipProperties
public class BookedFor {

    @Id
    @GeneratedValue(UUIDStringGenerator.class)
    public String rid;

    @Property
    private Date bookedDate;

}

which throws error as below:

The target class *.entities.BookedFor for the properties of the relationship BookedFor is missing a property for the generated, internal ID (@Id @GeneratedValue Long id) which is needed for safely updating properties

Note: If i use like following, it creates relationship with the internal id of neo4j

public interface BookedForRepository extends Neo4jRepository<BookedFor, Long> {}

@RelationshipProperties
public class BookedFor {

    @Id
    @GeneratedValue
    public Long id;

    @Property
    private Date bookedDate;

}

but this will create uncertainty on data migration / data mutation as we rely on internal id of neo4j relationship entity. Please correct me if i'm wrong.

spring data neo4j doc ref

Could anyone please help to proceed with this in a better way?

Also, please comment if more clarification / details required.

Upvotes: 0

Views: 1369

Answers (1)

meistermeier
meistermeier

Reputation: 8262

You cannot access relationship properties directly via repositories. Those classes are just an encapsulation for properties on relationships and are not meant to represent a "physical" relationship or more a relationship entity. Repositories are for @Node annotated classes solely.

If you want to access and modify the properties of a relationship, you have to fetch the relationship defining entity. A relationship on its own is always represented by its start and end node.

The lately introduced required @Id is for internal purposes only. If you have a special need to persist an id-like property on the relationship, it would be just another property in the @RelationshipProperties annotated class.

Upvotes: 2

Related Questions