Java Interop: Problems with primitives


#1

I'm working on a pet project with Kotlin and Spring Data Neo4j (I'll add support for Neo4j in KotlinPrimavera for upcoming releases)

So, I create a data class with some annotations

[NodeEntity]
data class User(
  [Indexed]
  [GraphProperty]
  var userId: String,
  [GraphId]
  var nodeId: Long = 0,
  var name: String,
  [RelatedTo(type = “IS_FRIEND_OF”, direction = Direction.BOTH, elementClass=javaClass<User>())]
  var friends: Set<User>? = null,
  [RelatedToVia(type = “HAS_SEEN”, elementClass=javaClass<Viewing>())]
  var views: Set<Viewing>? = null,
  var referredBy: User? = null)

When I try to save an instance of this class, Spring Neo4j show me this error

Exception in thread “main” org.springframework.data.mapping.model.MappingException: The type of the id-property in long nodeId rel: false idx: false must not be a primitive type but an object type like java.lang.Long

Seems that Kotlin compiler convert the jet.Long in a primitive long.

There is a way to override this behaviour? Using java.lang.Long explicitly don’t work


#2

java.lang.Long works for me, although you can't assign 0 to it.

A simple workaround would be to say “Long?” instead of “Long”.


#3

That's weird, the trick with the nullable type works fine (I can see this var as a java.lang.Long in the debugger) but Spring Data Neo4j keeps complaining :(


#4

Is it still saying that the type is "long"?


#5

I test every possible combination: Change this class to Java, A pure Java example, A mix of Kotlin and Java... And I can't make this work. Seems like a problem with Spring Data Neo4j, maybe a problem with libraries or config.

I’ll research more and put a proper solution here, at this moment not a Kotlin problem.

BTW, The integration between Java and Kotlin is sweet, easy as pie