1:1 relationship in SDN is not deleting old relationship

28 views
Skip to first unread message

Abdul Azeez Shaik

unread,
Oct 10, 2012, 3:10:48 PM10/10/12
to ne...@googlegroups.com
Hi,

I have a following NodeEntity,
Class User {
Status s;
}

I have created a new user and added a status to s'. Everything worked fine.
Next time i got the user and added a new status to 's'. What is the intended behavior?

I was expecting that old relationship with old 's' will get deleted and new relationship will get established with new 's'.
However, right now, old relationship is still intact and new relationship is being created.

Can you please let me know if it is intended behavior? If yes, then how do i achieve the removing old one and adding new one in one query, otherwise, i have to first remove the old one and add new one in another query.

Kindly suggest.

Thanks,
Abdul

Abdul Azeez Shaik

unread,
Oct 11, 2012, 8:55:39 AM10/11/12
to ne...@googlegroups.com
Any reply on this?

Michael Hunger

unread,
Oct 11, 2012, 9:03:53 AM10/11/12
to ne...@googlegroups.com
Yes, 

the old relationship should be deleted, (aka an outgoing relationship named "s" from the current user to another status.

What versions do you use?

Can you show the code where you change the relationship?

Thanks

Michael

--
 
 

Abdul Azeez Shaik

unread,
Oct 11, 2012, 10:25:06 AM10/11/12
to ne...@googlegroups.com
Hi Michael,

I am using latest 2.1.0.RC4 and Neo4j 1.8GA,
Here is the code,

StatusUpdateData userupdate = statusRepo.getlatestStatusUpdate(username);

if(null == userupdate) {

error.append("No user found");

return null;

}

StatusUpdate newUpdate = new StatusUpdate(statusupdate);

User user = userupdate.getUser();

if(null == user) {

return null;

}

newUpdate.setAddedBy(user);

StatusUpdate oldupdate = userupdate.getUpdate();

if(null != oldupdate) {

newUpdate.setStatus(oldupdate);

}


Here is my NodeEntity class,

public class StatusUpdate {

.....

@RelatedTo(type="NEXT", direction = Direction.OUTGOING)

StatusUpdate status;

@RelatedTo(type="STATUS", direction = Direction.INCOMING)

User addedBy;

.....
}

Here is the query on repository which am using in first line above,

@Query("START user=node:search(username={0}) MATCH user-[r?:STATUS]-update return update, user")

StatusUpdateData getlatestStatusUpdate(String username);

Here is my StatusUpdateData MapResult

@MapResult

public interface StatusUpdateData {


@ResultColumn("update")

StatusUpdate getUpdate();

@ResultColumn("user")

User getUser();

}

Kindly let me know if i have missed something here...

With all above code, am trying to achieve the below cypher query, I had to re-write the code in SDN, as i was not sure how to create index for new node in below query,

@Query("START n=node:search(username={0}) MATCH n-[r?:STATUS]->oldsu DELETE r " +

"WITH n,oldsu " +

"CREATE n-[:STATUS]->(newsu {statusid:{1},statusUpdate:{2},postedDate:{3},__type__:'org.netvogue.server.neo4japi.domain.StatusUpdate'}) " +

"WITH newsu, oldsu CREATE newsu-[:NEXT]->oldsu WHERE oldsu <> null RETURN newsu")


--
 
 

Abdul Azeez Shaik

unread,
Oct 11, 2012, 10:27:28 AM10/11/12
to ne...@googlegroups.com
Am saving the below data, using neo4jTemplate,

neo4jTemplate.save(newUpdate);

Michael Hunger

unread,
Oct 11, 2012, 9:15:45 PM10/11/12
to ne...@googlegroups.com
Your code is quite complex,
can you reproduce that behavior in a simple unit test?

Thanks a lot

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages