@@ -131,8 +131,8 @@ void doesFailOnRelationshipPropertiesWithMissingTargetNode() {
131
131
.withMessageContaining ("Missing @TargetNode declaration in" );
132
132
}
133
133
134
- @ Test // DATAGRAPH-2289
135
- void correctlyFindRelationshipObverse () {
134
+ @ Test // DATAGRAPH-2189
135
+ void correctlyFindRelationshipObverseSameEntity () {
136
136
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext ();
137
137
Neo4jPersistentEntity <?> persistentEntity = neo4jMappingContext .getPersistentEntity (EntityWithBidirectionalRelationship .class );
138
138
persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
@@ -141,15 +141,60 @@ void correctlyFindRelationshipObverse() {
141
141
});
142
142
}
143
143
144
- @ Test // DATAGRAPH-2289
144
+ @ Test // DATAGRAPH-2189
145
+ void correctlyFindRelationshipObverse () {
146
+ Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext ();
147
+ Neo4jPersistentEntity <?> persistentEntity = neo4jMappingContext .getPersistentEntity (EntityWithBidirectionalRelationshipToOtherEntity .class );
148
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
149
+ RelationshipDescription rd = (RelationshipDescription ) a ;
150
+ assertThat (rd .getRelationshipObverse ()).isNotNull ();
151
+ });
152
+ persistentEntity = neo4jMappingContext .getPersistentEntity (OtherEntityWithBidirectionalRelationship .class );
153
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
154
+ RelationshipDescription rd = (RelationshipDescription ) a ;
155
+ assertThat (rd .getRelationshipObverse ()).isNotNull ();
156
+ });
157
+ }
158
+
159
+ @ Test // DATAGRAPH-2189
145
160
void correctlyFindRelationshipObverseWithRelationshipProperties () {
161
+ Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext ();
162
+ Neo4jPersistentEntity <?> persistentEntity = neo4jMappingContext .getPersistentEntity (EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties .class );
163
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
164
+ RelationshipDescription rd = (RelationshipDescription ) a ;
165
+ assertThat (rd .getRelationshipObverse ()).isNotNull ();
166
+ });
167
+ persistentEntity = neo4jMappingContext .getPersistentEntity (OtherEntityWithBidirectionalRelationship .class );
168
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
169
+ RelationshipDescription rd = (RelationshipDescription ) a ;
170
+ assertThat (rd .getRelationshipObverse ()).isNotNull ();
171
+ });
172
+ }
173
+
174
+ @ Test // DATAGRAPH-2189
175
+ void correctlyFindSameEntityRelationshipObverseWithRelationshipProperties () {
146
176
Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext ();
147
177
Neo4jPersistentEntity <?> persistentEntity = neo4jMappingContext .getPersistentEntity (EntityWithBidirectionalRelationshipProperties .class );
148
178
persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
149
179
RelationshipDescription rd = (RelationshipDescription ) a ;
150
180
assertThat (rd .getRelationshipObverse ()).isNotNull ();
151
181
});
152
182
}
183
+
184
+ @ Test // DATAGRAPH-2189
185
+ void correctlyDontFindRelationshipObverse () {
186
+ Neo4jMappingContext neo4jMappingContext = new Neo4jMappingContext ();
187
+ Neo4jPersistentEntity <?> persistentEntity = neo4jMappingContext .getPersistentEntity (EntityLooksLikeHasObserve .class );
188
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
189
+ RelationshipDescription rd = (RelationshipDescription ) a ;
190
+ assertThat (rd .getRelationshipObverse ()).isNull ();
191
+ });
192
+ persistentEntity = neo4jMappingContext .getPersistentEntity (OtherEntityLooksLikeHasObserve .class );
193
+ persistentEntity .doWithAssociations ((AssociationHandler <Neo4jPersistentProperty >) a -> {
194
+ RelationshipDescription rd = (RelationshipDescription ) a ;
195
+ assertThat (rd .getRelationshipObverse ()).isNull ();
196
+ });
197
+ }
153
198
}
154
199
155
200
@ Nested
@@ -522,11 +567,73 @@ static class EntityWithBidirectionalRelationship {
522
567
@ Relationship ("KNOWS" )
523
568
List <EntityWithBidirectionalRelationship > knows ;
524
569
525
- @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
570
+ @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
526
571
List <EntityWithBidirectionalRelationship > knownBy ;
527
572
528
573
}
529
574
575
+ @ Node
576
+ static class EntityWithBidirectionalRelationshipToOtherEntity {
577
+
578
+ @ Id @ GeneratedValue
579
+ private Long id ;
580
+
581
+ @ Relationship ("KNOWS" )
582
+ List <OtherEntityWithBidirectionalRelationship > knows ;
583
+
584
+ }
585
+
586
+ @ Node
587
+ static class OtherEntityWithBidirectionalRelationship {
588
+
589
+ @ Id @ GeneratedValue
590
+ private Long id ;
591
+
592
+ @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
593
+ List <EntityWithBidirectionalRelationshipToOtherEntity > knownBy ;
594
+
595
+ }
596
+
597
+ @ Node
598
+ static class EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties {
599
+
600
+ @ Id @ GeneratedValue
601
+ private Long id ;
602
+
603
+ @ Relationship ("KNOWS" )
604
+ List <OtherEntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties > knows ;
605
+
606
+ }
607
+
608
+ @ Node
609
+ static class OtherEntityWithBidirectionalRelationshipWithRelationshipProperties {
610
+
611
+ @ Id @ GeneratedValue
612
+ private Long id ;
613
+
614
+ @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
615
+ List <EntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties > knownBy ;
616
+
617
+ }
618
+
619
+ @ RelationshipProperties
620
+ static class OtherEntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties {
621
+ @ Id @ GeneratedValue
622
+ private Long id ;
623
+
624
+ @ TargetNode
625
+ OtherEntityWithBidirectionalRelationshipWithRelationshipProperties target ;
626
+ }
627
+
628
+ @ RelationshipProperties
629
+ static class EntityWithBidirectionalRelationshipWithRelationshipPropertiesProperties {
630
+ @ Id @ GeneratedValue
631
+ private Long id ;
632
+
633
+ @ TargetNode
634
+ EntityWithBidirectionalRelationshipToOtherEntityWithRelationshipProperties target ;
635
+ }
636
+
530
637
@ Node
531
638
static class EntityWithBidirectionalRelationshipProperties {
532
639
@@ -536,7 +643,7 @@ static class EntityWithBidirectionalRelationshipProperties {
536
643
@ Relationship ("KNOWS" )
537
644
List <BidirectionalRelationshipProperties > knows ;
538
645
539
- @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
646
+ @ Relationship (type = "KNOWS" , direction = Relationship .Direction .INCOMING )
540
647
List <BidirectionalRelationshipProperties > knownBy ;
541
648
542
649
}
@@ -551,4 +658,22 @@ static class BidirectionalRelationshipProperties {
551
658
EntityWithBidirectionalRelationshipProperties target ;
552
659
}
553
660
661
+ @ Node
662
+ static class EntityLooksLikeHasObserve {
663
+ @ Id @ GeneratedValue
664
+ private Long id ;
665
+
666
+ @ Relationship ("KNOWS" )
667
+ private List <OtherEntityLooksLikeHasObserve > knows ;
668
+ }
669
+
670
+ @ Node
671
+ static class OtherEntityLooksLikeHasObserve {
672
+ @ Id @ GeneratedValue
673
+ private Long id ;
674
+
675
+ @ Relationship ("KNOWS" )
676
+ private List <EntityLooksLikeHasObserve > knows ;
677
+ }
678
+
554
679
}
0 commit comments