Neo4j和失去的关系

时间:2016-04-05 10:27:28

标签: neo4j spring-data-neo4j-4 neo4j-ogm

我有一个非常奇怪的neo4j行为。有时候,我现在无法重现这个问题,两个节点之间的关系就会丢失。

例如,我有这些节点:

@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;   
}

有时,当我更改相同的用户属性时,“managed_by”关系将丢失。

我看不出问题...也许UserEntity中没有传入的关系?它总是需要吗?

谢谢!

更新

简化我修改实体的代码:

@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);
    }
}

有时在调用更新控制器后我有:

  • 修改了用户实体
  • 未修改工作者实体(可能是两次调用之间的例外)
  • managed_by关系已删除!!!!

更新

几天后问题再次发生,现在我有更多日志

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

从日志中可以看出,在“刷新开始节点...”之后,neo4j删除了“managed_by”的关系。

我希望这些日志可以帮助您找到解释!

更新

其他一些日志

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}]}

保存实体时会出现此问题。实体(POJO)没有对WorkerEntity的引用,为什么neo4j说

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)

什么是context-init?

0 个答案:

没有答案