jpa - Need help converting Neo4j Cypher request to JPQL -
i have neo4j cypher request need convert jpql:
match (p:person)-[:worksfororganisation]-> (:organisation)-[*0..2]->(:organisation) -[:possessesresource|:accessesresource|:supportsresource]->(:software) <-[:categorycontains]-(c:resourcecategory) id(p)=({personid}) return c
this request starts unique person
identifier personid
.
we know person works 1 (in rare cases, many) organisation
s.
we know each organisation can possess, access or support resource of type software
.
we want return resourcecategories
"contain" software
s person can use, given fact there may associations between different organisations, grant him/her right use software organisation.
the difficulties convert jpql come :
- (:organisation)-[*0..2]->(:organisation)
- (:organisation)-[:possessesresource|:accessesresource|:supportsresource]->(:software)
point 1 : (:organisation)-[*0..2]->(:organisation)
means optional relationship between @ 3 "organisation" nodes. idea that, having found "organisation" node, interested paths starting @ 2 other "organisations" associated organisation person working for.
point 2 : (:organisation)-[:possessesresource|:accessesresource|:supportsresource]->(:software)
means that, having found "organisation", can related "software" 3 kinds of relationships (or many relationships of various kinds).
my idea far (really incomplete, know) :
@query("select rc person p, organisation o1, organisation o2, organisation o3, software s, resourcecategory rc " + "where p.id = :personid " + "and o1 member of p.worksfororganisations " + "and s member of rc.resources") set<resourcecategoryentity> getcategoriesforperson(@param("personid") long personid);
questions :
- how can reproduce [*0..2] optional relationships? need union between 3 requests, 1 organisation o1, second organisations o1 , o2, last 1 organisations o1, o2 , o3?
- can various kinds of relationships converted "and ((s member of o1.possessesresource) or (s member of o1.accessesresource) or (s member of o1.supportsresource r))"?
thanks!
update : jpql doesn't support union, how can reproduce "variable length join"?
after a lot of work, believe found corresponding jpql request.
in case wonders how mimic difficult part of cypher request, path of variable length (organisation)-[*0..2]->(organisation)
, believe cannot in jpql @ all, , had treat possible instances of super class "organisation", "community", "institution", "teachingdepartment" , "administrativedepartment".
select distinct (rc) resourcecategory rc join rc.resources d d.id in ( select e.id documentation e, organisation o, person u u.id = :personid , o member of u.worksfororganisations , ( o = e.organisationpossessingresource or o = e.organisationsupportingresource or o member of e.organisationshavingaccesstoresource ) ) or d.id in ( select d.id documentation d, organisation o type(o) in (institution) , ( o = d.organisationpossessingresource or o = d.organisationsupportingresource or o member of d.organisationshavingaccesstoresource ) , o.id in ( select i.id institution i, administrativedepartment ad, person u u.id = :personid , ad member of u.worksfororganisations , ad member of i.administrativedepartments ) ) or d.id in ( select d.id documentation d, organisation o type(o) in (institution) , ( o = d.organisationpossessingresource or o = d.organisationsupportingresource or o member of d.organisationshavingaccesstoresource ) , o.id in ( select i.id institution i, teachingdepartment td, person u u.id = :personid , td member of u.worksfororganisations , td member of i.teachingdepartments ) ) or d.id in ( select d.id documentation d, organisation o type(o) in (community) , ( o = d.organisationpossessingresource or o = d.organisationsupportingresource or o member of d.organisationshavingaccesstoresource ) , o.id in ( select c.id community c, institution i, administrativedepartment ad, person u u.id = :personid , ad member of u.worksfororganisations , ad member of i.administrativedepartments , c member of i.communities ) ) or d.id in ( select d.id documentation d, organisation o type(o) in (community) , ( o = d.organisationpossessingresource or o = d.organisationsupportingresource or o member of d.organisationshavingaccesstoresource ) , o.id in ( select c.id community c, institution i, teachingdepartment td, person u u.id = :personid , td member of u.worksfororganisations , td member of i.teachingdepartments , c member of i.communities ) ) or d.id in ( select d.id documentation d, organisation o type(o) in (community) , ( o = d.organisationpossessingresource or o = d.organisationsupportingresource or o member of d.organisationshavingaccesstoresource ) , o.id in ( select c.id community c, institution i, person u u.id = :personid , member of u.worksfororganisations , member of c.institutions ) )
foot-note : demonstrates cypher absolutely rock, being simpler equivalent jpql. become standard, reason why had switch relational database 1 day disappear.
Comments
Post a Comment