У меня есть этот сценарий, когда один посетитель создает запрос на посещение для резидента. Затем на основании ответа, предоставленного резидентом, визит либо одобряется, либо отклоняется. Но перед созданием нового запроса также существует вероятность того, что Посетитель мог получить от Резидента разрешение на постоянное одобренное посещение, и в этом случае мне не нужно проходить цикл утверждения.
Я хочу смоделировать свои сущности таким образом, чтобы я мог использовать наследование, а также, при этом отношение «ожидающий визит-запрос» создается от посетителя к резиденту, а одобрение/неодобрение происходит от резидента к посетителю.
Вот общий класс 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<>();
Вот общие отношения Visit, 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: