2

I'm asking if this is doable in Spring-Data-Neo4j (SDN) or Neo4j OGM because I understand that SDN actually uses Neo4j-OGM underneath.

Assume I have 2 Java objects that I need to map to a single Graph node:

@NodeEntity
public class User {
    @GraphId
    private Long id;
    private ComplexInfo info;
}
@NodeEntity
public class ComplexInfo {
    @GraphId
    private Long id;
    private Long age;
    private String name;
}

This way, I'll have a relation between 2 nodes. User and ComplexInfo.

But is there a way to map this as a single node, where the primitive variables (including String and wrapper Objects such as Long, Integer..etc) of the ComplexInfo java object would be persisted within the User node and there would be no existence of the ComplexInfo node ?

Effectively it would be as if I have mapped my User object this way:

@NodeEntity
public class User {
    @GraphId
    private Long id;
    private Long age;
    private String name;
}

I don't want to have 2 nodes for this because the ComplexInfo class is no more than a collection of reusable properties and there is no benefit of having a relationship between it and the node having this properties.

1
  • 1
    This is posible only in the latest OGM - 2.1.0-SNAPSHOT release. You can chek this question for more info. I hope to see 2.1.0 release soon, I'm waiting for this improvement as well. Commented Nov 16, 2016 at 8:26

1 Answer 1

2

I'm assuming here that you are after embedding the ComplexInfo class into the User class. To be clear this means that ComplexInfo will not appear in the database as a node and cannot be directly looked up through the OGM; it must always be accessed through composition of an annotated domain object.

As @troig mentions the only way to do this is to upgrade to the latest snapshot version of the OGM (2.1 GA will be out around 12th December). You can then follow Jasper's example here. It should be pretty easy to work with your domain. Just remember to remove the @NodeEntity annotation and the @GraphId Long id field in ComplexInfo.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi @digx1! Any news about the expected 2.1 GA release? Thanks
@troig. It was released on the 12th as planned: mvnrepository.com/artifact/org.neo4j/neo4j-ogm-core/2.1.0
Thanks a lot for your reply @digx1! I wasn't looking in the right place... github.com/neo4j/neo4j-ogm/releases

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.