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?