java-driver icon indicating copy to clipboard operation
java-driver copied to clipboard

DAO not working in Kotlin

Open CustomEntity opened this issue 2 years ago • 2 comments

Hello ! I'm using the Java Driver in Kotlin and I get this error with this DAO:

@Dao
interface UserDao {

    @Select
    suspend fun findById(
        id: Snowflake?
    ): Deferred<User?>

    @Insert
    suspend fun save(
        user: User
    ): Deferred<Void?>
}

Error:

error: [UserDao] Unexpected error while writing generated code: java.lang.NullPointerException: Cannot invoke "javax.lang.model.element.TypeElement.asType()" because "classElement" is null
public abstract interface UserDao {

Here's my build.gradle for versions:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.7.22'
    id 'io.ktor.plugin' version '2.2.1'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.22'
    id "com.google.devtools.ksp" version "1.7.21-1.0.8"
}

apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'

group "fr.kettl"
version "0.0.1"
mainClassName = "fr.kettl.launcher.Launcher"

def koin_ksp_version = "1.1.0"
def ksp_version = "1.7.21-1.0.8"
def koin_version= "3.3.2"
def koin_ktor = "3.3.0"
def scylla_maven_version = "4.14.1.0"

def isDevelopment = project.ext.has("development")
applicationDefaultJvmArgs = ["-Dio.ktor.development=$isDevelopment"]

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation "io.ktor:ktor-server-core-jvm:$ktor_version"
    implementation "io.ktor:ktor-server-swagger:$ktor_version"
    implementation "io.ktor:ktor-server-content-negotiation-jvm:$ktor_version"
    implementation "io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version"
    implementation "io.ktor:ktor-server-auth-jvm:$ktor_version"
    implementation "io.ktor:ktor-server-auth-jwt-jvm:$ktor_version"
    implementation "io.ktor:ktor-server-sessions-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-apache-jvm:$ktor_version"
    implementation "io.ktor:ktor-server-netty-jvm:$ktor_version"
    implementation "ch.qos.logback:logback-classic:$logback_version"
    implementation "io.insert-koin:koin-ktor:$koin_ktor"
    implementation "io.insert-koin:koin-core:$koin_version"
    implementation "io.insert-koin:koin-annotations:$koin_ksp_version"
    ksp "io.insert-koin:koin-ksp-compiler:$koin_ksp_version"
    testImplementation "io.ktor:ktor-server-tests-jvm:$ktor_version"
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testImplementation 'io.ktor:ktor-server-test-host-jvm:2.2.1'

    kapt "com.scylladb:java-driver-mapper-processor:$scylla_maven_version"
    implementation "com.scylladb:java-driver-core:$scylla_maven_version"
    implementation "com.scylladb:java-driver-query-builder:$scylla_maven_version"
    implementation "com.scylladb:java-driver-mapper-runtime:$scylla_maven_version"
}

CustomEntity avatar Jan 12 '23 19:01 CustomEntity

Hi, I'm not really familiar with Kotlin, but I tried replicating this. It seems to me this problem is related to the bug with default interface methods (KT-4779) and what you need to do is use a workaround recommended in docs. Check out the example linked in the paragraph about KT-4779.

Bouncheck avatar Feb 13 '23 12:02 Bouncheck

Hi, I'm not really familiar with Kotlin, but I tried replicating this. It seems to me this problem is related to the bug with default interface methods (KT-4779) and what you need to do is use a workaround recommended in docs. Check out the example linked in the paragraph about KT-4779.

@CustomEntity - did the above help?

mykaul avatar Mar 06 '23 08:03 mykaul

Closed as not responsive.

roydahan avatar Jun 13 '24 13:06 roydahan