0

我有这种情况,其中一位访问者向居民创建了一个待处理的访问请求。然后根据居民提供的答复,访问被批准或拒绝。但在创建新请求之前,访客也有可能已获得居民的永久批准访问许可,在这种情况下,我不需要经历审批周期。

我想以一种可以使用继承的方式对我的实体进行建模,其中,待定访问请求关系是从访问者到居民创建的,而批准/不批准是从居民到访问者发生的。

这是通用的 Person 类:

public abstract class Person extends Entity {

    @Property private String name;

    @Property private String mobileNumber;

    @Property private String emailAddress;

    @Property private String aadhardId;
}

请注意,Entity 类与 spring-OGM 示例中的相同。这是一个设置了关系类型的居民:

@NodeEntity(label = "Resident")
public class Resident extends Person {

    @Autowired
    Session session;

    @Relationship(type = "PENDING-VISIT", direction = Relationship.INCOMING)
    Set<PendingVisit> pendingVisits = new HashSet<>();

    @Relationship(type = "PERMANENTLY-APPROVED-VISIT", direction = Relationship.OUTGOING)
    Set<PermanentlyApprovedVisit> permanentlyApprovedVisits = new HashSet<>();

和访客:

@NodeEntity(label="Visitor")
public  class Visitor extends Person {

    @Autowired
    ResidentRepository residentRepository;

    @Relationship(type = "PENDING-VISIT", direction = Relationship.OUTGOING)
    private Set<PendingVisit> pendingVisit = new HashSet<>();

    public Set<PendingVisit> getPendingVisits() {
        return pendingVisit;
    }


    @Relationship(type = "PERMANENTLY-APPROVED-VISIT",direction = Relationship.INCOMING)
    Set<PermanentlyApprovedVisit> permanentlyApprovedVisits = new HashSet<>();

以下是按顺序排列的通用访问、PendingVisit 和 PermanentlyApprovedVisit 关系:

公共抽象类访问{

@GraphId   private Long visitId;

@StartNode private T visitRequester;

@EndNode   private R visitResponder;

@Property  private Date dov;

@RelationshipEntity(type="PENDING-VISIT")
public class PendingVisit extends Visit<Visitor, Resident> {

    public PendingVisit(Visitor visitor, Resident resident){
        super(visitor,resident);
    }

}

@RelationshipEntity(type="PERMANENTLY-APPROVED-VISIT")
public class PermanentlyApprovedVisit extends Visit<Resident,Visitor> {

    private final boolean permanentlyApproved = true;

    public PermanentlyApprovedVisit(Resident resident, Visitor visitor){
        super(resident,visitor);
    }

}

在尝试创建 pendingVisit 时,我首先要检查 PErmanentlyApprovedVisit 关系是否已经存在。我正在编写测试,这就是我测试的方式:

Optional<PermanentlyApprovedVisit> permanentlyApprovedVisit = Optional.ofNullable(residentRepository.findIfVistorApprovedPermanentlyByResident(resident.getId(), this.getId()));
        if(permanentlyApprovedVisit.isPresent())
            return permanentlyApprovedVisit.get();

最后,这是 ResidentRepository 方法:

@Query(" OPTIONAL MATCH (resident:Resident)-[r:PERMANENTLY-APPROVED-VISIT]→(visitor:Visitor)"+
           " WHERE resident.id = {residentId} AND visitor.id = {visitorId}"+
            "RETURN r")
    public PermanentlyApprovedVisit findIfVistorApprovedPermanentlyByResident(@Param("residentId")long residentId, @Param("visitorId") long visitorId);

但是,当我运行它时,我不断收到这个异常:

org.neo4j.ogm.session.result.ResultProcessingException: Could not initialise res
ponse
        at org.neo4j.ogm.session.response.JsonResponse.parseErrors(JsonResponse.
java:165)
        at org.neo4j.ogm.session.response.JsonResponse.parseColumns(JsonResponse
.java:139)
        at org.neo4j.ogm.session.response.JsonResponse.initialiseScan(JsonRespon
se.java:75)
        at org.neo4j.ogm.session.response.GraphModelResponse.initialiseScan(Grap
hModelResponse.java:69)
        at org.neo4j.ogm.session.response.GraphModelResponse.<init>(GraphModelRe
sponse.java:39)
        at org.neo4j.ogm.session.request.SessionRequestHandler.execute(SessionRe
questHandler.java:57)
        at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(
ExecuteQueriesDelegate.java:118)
        at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQ
ueriesDelegate.java:76)
        at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject
(ExecuteQueriesDelegate.java:50)
        at org.neo4j.ogm.session.Neo4jSession.queryForObject(Neo4jSession.java:3
30)
        at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.
execute(GraphRepositoryQuery.java:73)
        at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.
execute(GraphRepositoryQuery.java:50)
        at org.springframework.data.repository.core.support.RepositoryFactorySup
port$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:431)
        at org.springframework.data.repository.core.support.RepositoryFactorySup
port$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:409)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:179)
        at org.springframework.data.projection.DefaultMethodInvokingMethodInterc
eptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:179)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.
proceedWithInvocation(TransactionInterceptor.java:99)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.
invokeWithinTransaction(TransactionAspectSupport.java:281)
        at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:96)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:179)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterc
eptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:179)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:207)
        at com.sun.proxy.$Proxy106.findIfVistorApprovedPermanentlyByResident(Unk
nown Source)
        at visit.domain.Visitor.sendPendingVisitRequest(Visitor.java:62)
        at visit.domain.DomainTests.shouldCreatePendingVisit(DomainTests.java:89
)

我想在这里实现的那种建模有问题吗?我读了另一个线程,这是 Prev 和 Next 的问题:

Neo4j TimeTree REST API 上一个和下一个导航

4

1 回答 1

0

实际上,我通过引用我在单个 NodeEntities 中创建的集合而不是点击密码查询来解决这个问题。

于 2015-09-20T04:26:59.920 回答