Question

I want to represent this type of modeling with Spring Data Neo4j:

Object ------Value------> Property

...where Object and Property are NodeEntity, and where Value is a RelationshipEntity.

For instance:

Car1 ------String value="Ford"------> Brand
Car1 ------int value=20000------> Cost
Car2 ------int value=30000------> Cost
Car2 ------boolean value=true------> HasWheels

I know that I have the possibility to put all these properties directly in the car nodes. But I'd like to use this modeling instead for graph traversal optimization in the future. It would look like this:

@RelationshipEntity(type="PROPERTY_VALUE")
public class PropertyValue {
    @GraphId Long id;
    @StartNode Car car;
    @EndNode Property property;

    <???value_type???> value;

    public PropertyValue() {
    }
}

The problem is that I don't know which type I have to use for the value property. Is there any possibility to do that with Spring Data Neo4j?

Thank you.

Was it helpful?

Solution

If your types are all types that are supported in Neo4j you can use Object as target type. And the actual instance will then be stored as the appropriate type in Neo4j.

@RelationshipEntity(type="PROPERTY_VALUE")
public class PropertyValue {
    @GraphId Long id;
    @StartNode Car car;
    @EndNode Property property;

    @GraphProperty
    Object value;

    public PropertyValue() {
    }
}

OTHER TIPS

Could you not use generics?

Property<T> {

...
T value();

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top