cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

SDN 6.0.3 -- saving a new relationship breaks existing dynamically-named relationships

I'm creating a website where logged in users can have a blog. My mid-tier is Spring Java so I'm using SDN 6.0.3 to try to take advantage of the SDN-RX dynamic relationship handling.

My Neo4j Desktop version is 1.4.1 and the database version is 4.2.2.

In the first image, each user (large orange) has a blog, and each blog has 3 posts with relationships that are named dynamically in the format suggested by Max De Marzi here:

In this image, blog test1 is friended to test3 and test4, and blog test4 is friended to test1 and test2. (No one is yet friended to test 5).

This is how my Blog class handles friend and blocking relationships.

	@Relationship(type = "IS_BLOCKING", direction = Direction.OUTGOING)
	private List<Blog> blogsBlocked = new ArrayList<Blog>();

	@Relationship(type = "IS_FRIENDED_TO", direction = Direction.OUTGOING)
	private List<Blog> blogsFriended = new ArrayList<Blog>();

This is how I've understood I should handle the dynamically named blog post relationships:

private Map<String, List<BlogPost>> allPosts = new HashMap<>();

I want to have the ability for users to block other users, so I tried to have test1 block test2, which resulted in the second image.

The block worked correctly, but each blog participating in the block lost its dynamically named relationships, and one regular friend relationship (between test1 and test3) was severed.

I really hope I'm not missing something obvious; I've searched on this forum and in stackoverflow for a couple of days but haven't been able to find an example that seems to explain the error I'm experiencing. I have seen a few issue reports (for example Support RelationshipProperties in dynamic relationships [DATAGRAPH-1385] · Issue #1947 · spring-proj...) that suggest that dynamic relationships may have some issues in general, which is why I moved away from having a relationship entity with properties for the time being.

I just started learning Neo4j in my spare time in 2020, so is this a known issue or do I have an error in my code?

Barring that, is there a way I can work around this with dynamic relationships in earlier versions of SDN, perhaps slightly more object-mapped than De Marzi's fine example?

Grateful in advance for any assistance anyone can give!

EDITED TO ADD: Tried the block just now with no posts in any of the tests blogs and test1 still lost its friendship to test3 so it's probably something I'm doing wrong. Any pointers for a newbie would be wonderful.

1 ACCEPTED SOLUTION

UPDATE: I consider this resolved for now. I fixed my 2 separate issues, so let me explain if anyone else is having the same issue.

  1. Regular relationships being removed as new ones are added -- this appeared to be cause by a conflict during the transaction. I resolved this by putting the smallest possible unit of work into a function and calling it from the main method.

  2. Dynamically-typed relationships being removed as new regular relationships are added -- since I took the nuclear option and stepped down to SDN 5.3.6.RELEASE I can't say that I completely resolved or diagnosed this issue. But I did step around it for now by just having a regular "legacy posts" relationship, having each post record its formatted date in a String for searchability, then searched specifically for posts containing that date.

@Query("MATCH (b:Blog)-[r]->(bp:BlogPost) WHERE b.blogId = $blogId AND bp.legacyDateSort = $legacyDateSort RETURN collect(bp)")
	List<BlogPost> findLegacyPostsOnDate(@Param("blogId") String blogId, @Param("legacyDateSort")String legacyDateSort);

While it's not terribly elegant, it'll get me through for now and I can switch over to the new dynamic relationship type method once the SDN 6 release stabilizes a bit more.

View solution in original post

1 REPLY 1

UPDATE: I consider this resolved for now. I fixed my 2 separate issues, so let me explain if anyone else is having the same issue.

  1. Regular relationships being removed as new ones are added -- this appeared to be cause by a conflict during the transaction. I resolved this by putting the smallest possible unit of work into a function and calling it from the main method.

  2. Dynamically-typed relationships being removed as new regular relationships are added -- since I took the nuclear option and stepped down to SDN 5.3.6.RELEASE I can't say that I completely resolved or diagnosed this issue. But I did step around it for now by just having a regular "legacy posts" relationship, having each post record its formatted date in a String for searchability, then searched specifically for posts containing that date.

@Query("MATCH (b:Blog)-[r]->(bp:BlogPost) WHERE b.blogId = $blogId AND bp.legacyDateSort = $legacyDateSort RETURN collect(bp)")
	List<BlogPost> findLegacyPostsOnDate(@Param("blogId") String blogId, @Param("legacyDateSort")String legacyDateSort);

While it's not terribly elegant, it'll get me through for now and I can switch over to the new dynamic relationship type method once the SDN 6 release stabilizes a bit more.