4

I have a very strange behavior of neo4j. Sometimes, and I can't reproduce the issue now, the relationship between two nodes is lost.

For example I have these nodes:

@NodeEntity(label = "Worker")
public class WorkerEntity {
    @GraphId
    private Long mId;

    @Relationship(type = "managed_by")
    private Iterable<UserEntity> mUsers;    
}

@NodeEntity(label = "User")
public class UserEntity {
    @GraphId
    private Long mId;

    @Property(name = "name")
    private String mName;   
}

Sometimes when I change same user properties, the relationship "managed_by" is lost.

I can't see the problem...maybe the absence of the incoming relationship in UserEntity? Is it always required?

Thank you!

UPDATE

Simplifying the code where I modify the entities:

@RestController
public class WorkerCtrl {
    public void update() {
        mUserService.update();
        mWorkerService.update();
    }
}

@Service
public class UserService {
    @Transactional
    public void update() {
        UserEntity lUser = mUserDao.findById(...);
        lUser.setName(...);
        mUserDao.save(lUser);
    }
}

@Service
public class WorkerService {
    @Transactional
    public void update() {
        WorkerEntity lWorker = mWorkerDao.findById(...);
        lWorker.setName(...);
        mWorkerDao.save(lWorker);
    }
}

Sometimes after the call to update of the controller I have:

  • user entity modified
  • worker entity NOT modified (maybe an exception between the two calls)
  • managed_by relationship deleted!!!!

UPDATE

After some days the issue is occurred another time and now I have more logs

08:49:07 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] flushing end node of: ($6476)-[:managed_by]->($6477)
08:49:07 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] flushing start node of: ($6476)-[:managed_by]->($6477)
08:49:07 -04:00 DEBUG [org.neo4j.ogm.session.request.SessionRequestHandler] {"statements":[{"statement":"MATCH ($6476)-[_0:`managed_by`]->($6477) WHERE id($6476)={$6476} AND id($6477)={$6477} DELETE _0","parameters":{"$6477":6477,"$6476":6476},"resultDataContents":["row"],"includeStats":false}]}
08:49:07 -04:00 DEBUG [org.neo4j.ogm.session.request.DefaultRequest] POST https://db-*****************.graphenedb.com:24780/db/data/transaction/28723, request: {"statements":[{"statement":"MATCH ($6476)-[_0:`managed_by`]->($6477) WHERE id($6476)={$6476} AND id($6477)={$6477} DELETE _0","parameters":{"$6477":6477,"$6476":6476},"resultDataContents":["row"],"includeStats":false}]}
08:49:07 -04:00 DEBUG [org.neo4j.ogm.session.request.DefaultRequest] Response is OK, creating response handler

As you can see from logs, after "flushing start node of..." the relationship "managed_by" is deleted by neo4j.

I hope these logs can help you to find an explanation!

UPDATE

Some other log

14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($11989)-[:managed_by]->($11990)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($14040)-[:managed_by]->($14041)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($5672)-[:managed_by]->($5673)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($4560)-[:managed_by]->($4561)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($5490)-[:managed_by]->($5491)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($4412)-[:managed_by]->($4413)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($9494)-[:managed_by]->($9495)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($4446)-[:managed_by]->($4447)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($5158)-[:managed_by]->($5159)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($9301)-[:managed_by]->($9302)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($4086)-[:managed_by]->($4087)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-init: ($3528)-[:managed_by]->($3529)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context initialised with 47 relationships
14:51:15 -04:00 DEBUG [org.neo4j.ogm.session.transaction.Transaction] commit invoked
14:51:15 -04:00 DEBUG [org.neo4j.ogm.session.transaction.TransactionManager] POST https://******************.graphenedb.com:24780/db/data/transaction/29375/commit
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] visiting: it.cedox.server.entity.UserEntity@1dc975d
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] it.cedox.server.entity.UserEntity@1dc975d has changed
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] mapping references declared by: it.cedox.server.entity.UserEntity@1dc975d 
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-del: ($4962)-[null:managed_by]->($4963)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.session.transaction.TransactionManager] Status code: 200
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] flushing end node of: ($4962)-[:managed_by]->($4963)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] flushing start node of: ($4962)-[:managed_by]->($4963)
14:51:15 -04:00 DEBUG [org.neo4j.ogm.session.transaction.TransactionManager] {"results":[],"errors":[]}
14:51:15 -04:00 DEBUG [org.neo4j.ogm.session.request.SessionRequestHandler] {"statements":[{"statement":"MATCH ($4963) WHERE id($4963)={$4963} SET $4963:`User`, $4963+={$4963_props}  WITH $4963 MATCH ($4962)-[_0:`managed_by`]->($4963) WHERE id($4962)={$4962} DELETE _0","parameters":{"$4962":4962,"$4963":4963,"$4963_props":{"lastName":"*******","enabled":true,"username":"********","firstAccessDate":null,"email":"**********","roles":"ADMIN","firstAccess":true,"changePassword":false,"firstName":"********","password":"********"}},"resultDataContents":["row"],"includeStats":false}]}

This issue occurs when I save the entity. The entity (POJO) doesn't have a reference to the WorkerEntity, so why neo4j said

14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] visiting: it.cedox.server.entity.UserEntity@1dc975d
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] it.cedox.server.entity.UserEntity@1dc975d has changed
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] mapping references declared by: it.cedox.server.entity.UserEntity@1dc975d 
14:51:15 -04:00 DEBUG [org.neo4j.ogm.mapper.EntityGraphMapper] context-del: ($4962)-[null:managed_by]->($4963)

What is context-init?

aGO
  • 1,263
  • 14
  • 30
  • When you change user properties and save- at that point, does mUsers contain data? Does UserEntity contain a reference to WorkerEntity and if so, are they in sync? – Luanne Apr 06 '16 at 04:58
  • The properties are sync but the reletionship is deleted – aGO Apr 06 '16 at 05:31
  • Can you share a small test that demonstrates the issue? Which version of SDN are you using? – Luanne Apr 06 '16 at 05:33
  • I can't share a test..it happens sometimes. The version is 4.0.0.RELEASE – aGO Apr 06 '16 at 05:42
  • k, can you share the code used to update the entity as well as both entities (with getters/setters etc. if they exist)? – Luanne Apr 06 '16 at 05:44
  • I updated the question. But the presence of relation (incoming and outcoming) is required on both entity or If is it not needed I can omit it like I have done in UserEntity? – aGO Apr 06 '16 at 08:33
  • It's okay if UserEntity does not have a reference to WorkerEntity. If WorkerEntity is not updated sometimes then it points to other problems, which I'm unable to figure out from the example. Are you loading entities to depth 0 by any chance before saving? – Luanne Apr 08 '16 at 03:34
  • I use the default behavior – aGO Apr 08 '16 at 05:58
  • I updated the question with more logs. I have the feeling the problem is connected to the depth of the save and the technique to auto discover the modified nodes and relationship – aGO Apr 19 '16 at 10:10
  • @aGO, have you resolved this ? – Muhammad Gelbana Dec 08 '16 at 05:39
  • @ago, any more details how you solved that issue? I'm experiencing similar problems.. :/ – wiesson Sep 10 '18 at 20:59
  • 1
    @wiesson sorry but don’t have news – aGO Sep 10 '18 at 21:03
  • Thanks for the quick reply. In our case it might happen during PATCH operations (merging objects) but I have just started to debug it. – wiesson Sep 10 '18 at 21:07
  • 1
    @wiesson I will check our code tomorrow and I will let you know how we bypassed the issue – aGO Sep 10 '18 at 21:11

0 Answers0