1

I would like to use Neo4j's new OGM library with idiomatic (ie, case classes, immutable) Scala classes for my domain objects.

Are there additional annotations I can use to make the following class work with Neo4j OGM? A country as defined below does not get persisted because the @GraphId isn't found. If I add a mutable graph id member var (already undesirable, but...) then an object is persisted but without the name property.

@NodeEntity 
case class Country (
  val name: String, 
  @GraphId val id: java.lang.Long = 0
)

Am I stuck with using Java-like classes with mutable properties for now?

Thanks! Steve

Steve Nester
  • 105
  • 8

1 Answers1

1

GraphIds should never have values assigned to them manually. That is probably the reason why the entity does not save as expected. Other than that I'm not familiar much with scala but a related thread on neo4j-ogm and scala is Neo4j OGM example with Scala

Community
  • 1
  • 1
Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Thanks. I actually modeled my working code on the other thread - was just hoping to make it more Scala-like. It appears that when an object is persisted the same object is returned with the id filled in. For Scala, where immutability is the "holy grail", I'd expect to see a copy of the original object returned, with the id filled in, thus preserving the immutability of the original object. (For some relevant Scala details, check out case classes, which I would use for my domain objects). But I do really like OGM and it is removing my dependency on Spring so I'm still happy. Thanks! – Steve Nester Jan 07 '16 at 20:48