Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue of storing inherited relationship entity #45

Closed
magoafono opened this issue Sep 18, 2015 · 0 comments
Closed

issue of storing inherited relationship entity #45

magoafono opened this issue Sep 18, 2015 · 0 comments
Assignees
Labels

Comments

@magoafono
Copy link

Dear all,
we are trying to store (and retrieve) two nodes (type A and B) linked by a relationship entity with a inhering type

    R (abstract)
    ^
    CR (concrete)
    |
A ====> B

Where R is the abstract @RelationshipEntity and the CR is the concrete @RelationshipEntity.

When we save the sub-graph A->CR->B the stored "real" types are A->R->B.

imgo

In other word, the abstract relationship type is used by OGM instead of the concrete one so the load fails.

Here the code:

@NodeEntity
public class A {
    private Long id;
    private R r;

    public R getR() {
        return r;
    }

    public void setR(R c) {
        this.r = c;
    }
}

@NodeEntity
public class B {
    private Long id;
}

@RelationshipEntity
public abstract class R {
    private Long id;

    @StartNode
    private A a;

    @EndNode
    private B b;

    public A getA() {
        return a;
    }

    public void setA(A a) {
        this.a = a;
    }

    public B getB() {
        return b;
    }

    public void setB(B b) {
        this.b = b;
    }

}

@RelationshipEntity
public class CR extends R {
 //some stuff here ...
}
import java.util.ArrayList;
import java.util.Collection;
import org.neo4j.ogm.session.Session;

public class Tester {

    public static void main(String[] args) {
        Tester tester = new Tester();
        tester.test4();
        tester.test5();
    }

    private void test4() {
        Session session = Neo4jSessionFactory.getNeo4jSession();
        session.beginTransaction();

        A a = new A();
        B b = new B();

        CR r = new CR();
        r.setA(a);
        r.setB(b);

        a.setR(r);

        session.save(a);

        session.getTransaction().commit();
    }

    private void test5() {
        Session session = Neo4jSessionFactory.getNeo4jSession();
        session.beginTransaction();

        Collection<A> as = session.loadAll(A.class);

        for (A a : as) {
            System.out.println(a.getR());
        }

        session.getTransaction().commit();
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants