Summary
Add support for specifying relationship direction (OUTGOING, INCOMING) and bidirectional relationships in the @RelationshipEntity annotation and related metadata classes.
Current Behavior
Currently, the @RelationshipEntity annotation only defines:
type - relationship type name
nodeType - single type for both source and target (requires same type)
sourceField / targetField - field names for endpoints
There is no concept of:
- Direction - relationships are implicitly directional but direction cannot be specified or controlled
- Bidirectional - no way to mark a relationship as traversable in both directions
- Heterogeneous node types - source and target must be the same type
Proposed Solution
1. Add Direction Enum
public enum RelationshipDirection {
OUTGOING, // (source)-[rel]->(target)
INCOMING, // (source)<-[rel]-(target)
BIDIRECTIONAL // traversable in both directions
}
- Extend @RelationshipEntity Annotation
@RelationshipEntity(
type = "FRIEND_OF",
sourceType = Person.class,
targetType = Person.class,
sourceField = "from",
targetField = "to",
direction = RelationshipDirection.BIDIRECTIONAL
)
public class FriendRelationship {
@Id
private String id;
private Person from;
private Person to;
private LocalDate since;
}
- Update RelationshipMetadata
- Add direction field
- Support different source and target types
- Generate direction-aware Cypher patterns
Use Cases
- Social Graph: Friendships are bidirectional - if A is friends with B, B is friends with A
- Hierarchical Data: Parent-child relationships where direction matters
- Mixed Entity Types: Person WORKS_AT Company where source and target are different types
Impact
- Breaking change: nodeType() could be deprecated in favor of sourceType()/targetType()
- Requires updates to RelationshipMetadata and query generation logic
- Consider backward compatibility for existing single-type relationships
Summary
Add support for specifying relationship direction (OUTGOING, INCOMING) and bidirectional relationships in the
@RelationshipEntityannotation and related metadata classes.Current Behavior
Currently, the
@RelationshipEntityannotation only defines:type- relationship type namenodeType- single type for both source and target (requires same type)sourceField/targetField- field names for endpointsThere is no concept of:
Proposed Solution
1. Add Direction Enum
Use Cases
Impact