Java Interop: Problems with primitives


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

data class User(
  var userId: String,
  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” 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


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”.


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 :(


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


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