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

@id annotation doesn't work after recompilation #158

Open
ddrozdov opened this issue May 24, 2016 · 9 comments
Open

@id annotation doesn't work after recompilation #158

ddrozdov opened this issue May 24, 2016 · 9 comments

Comments

@ddrozdov
Copy link
Contributor

I have an issue with the field annotated with @id.

If the case class declaration goes after the class that calls toCC, the id field is not filled in.
If I move the case class to the beginning of the file, everything works well.

It is not a big issue when all your code is in the single file, but when the case classes are in a separate file, the id is filled depending on the order the sources are compiled - sometimes it works and after the gradle clean it doesn't.

@mikolak-net
Copy link
Contributor

mikolak-net commented May 25, 2016

Sounds like it's related to #133 . IIRC @mpollmeier is working on an alternate shapeless-based (de)serializer to work around the problem.

@mpollmeier
Copy link
Owner

That's true.

@voroninp
Copy link

voroninp commented Sep 3, 2018

@id annotation is just not working independently of classes order =(

@mpollmeier
Copy link
Owner

@voroninp
Copy link

voroninp commented Sep 5, 2018

@mpollmeier could you a give me a hint what I am doing wrong? This test fails for me =(

@label("user")
case class UserWithId(@id id: Int, name: String, age: Int)

class GremlinQueriesSpec extends FlatSpec
  with ScalaFutures with MustMatchers with BeforeAndAfterAllConfigMap {

  behavior of "Gremlin queries"

  it must "add vertex with id" in {
    val user = new UserWithId(1, "anonymous", 35)

    val graph = TinkerGraph.open.asScala

    graph + user

    val vertex = graph.V(user.id).head().toCC[UserWithId]

    vertex must be eq user
  }
}

sbt.version=0.13.16
scalaVersion := "2.11.12"

@mpollmeier
Copy link
Owner

Hmm, this looks like a regression - it works fine until gremlin-scala 3.3.1.2. I'll have a look.

@mpollmeier
Copy link
Owner

Actually, this was tradeoff based on a design decision back then. I would have preferred if it worked both ways, but IMO it's best to leave id assignment to the graph.
Anyway, due to that tradeoff @id only works when reading the case class back out of the graph. I will update readme and tests to reflect that.
Here's a working version of your test:

@label("user")
case class UserWithId(name: String, age: Int, @id id: Option[Int] = None)

it must "add vertex" in {
  val graph = TinkerGraph.open.asScala
  val vertex = graph + new UserWithId("anonymous", 35)
  val user = graph.V(vertex.id).toCC[UserWithId].head
  println(user) // UserWithId(anonymous,35,Some(0))
}

mpollmeier added a commit that referenced this issue Sep 8, 2018
@voroninp
Copy link

@mpollmeier Unfortunately, not an option for us. =( We get ids from external system and they are UUIDs

@mpollmeier
Copy link
Owner

I'd say you have at least these alternatives:

  1. store them in a separate (indexed) property. That would be my preference, since it works with all graph dbs.
  2. only use the case class marshalling for retrieving them from the graph, and write them using the graph api.

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

No branches or pull requests

4 participants