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

kotlin: Java type mismatch on @Transactional during compile time #3477

Closed
jonaskahn opened this issue Jul 18, 2024 · 2 comments
Closed

kotlin: Java type mismatch on @Transactional during compile time #3477

jonaskahn opened this issue Jul 18, 2024 · 2 comments

Comments

@jonaskahn
Copy link

I have a simple controller like this one:

package io.github.jonaskahn.app.controller.authen

import io.github.jonaskahn.app.repositories.UsersRepository
import io.jooby.annotation.GET
import io.jooby.annotation.Path
import io.jooby.annotation.Transactional
import jakarta.inject.Inject

@Path("/auth")
class AuthenticationController @Inject constructor(private val userRepository: UsersRepository) {

    @GET("/token")
    @Transactional(true)
    fun generateToken(): String {
        val data = userRepository.findByUsername("admin")
        data?.fullName = "Jonas"
        data?.password = "1111"
        data?.let { userRepository.save(it) }
        return ""
    }
}

When I run compile, it throw me an error like
Java type mismatch expected (Mutable)Map<String!, Any!> but found (Mutable)Map<String!, Boolean!>!. Use explicit cast
I found out something went wrong with generate code in Jooby. Here is it:

@Throws(Exception::class)
override fun install(app: io.jooby.Jooby) {
     /** See [AuthenticationController.generateToken] */
     app.get("/auth/token", this::generateToken)
       .setAttributes(java.util.Map.of(
           "Transactional", true))
       .setReturnType(String::class.java)
       .setMvcMethod(AuthenticationController::class.java.getMethod("generateToken"))
   }

Could anyone help me overcome with this error?

@jonaskahn jonaskahn changed the title Java type missmatch on @Transactional during compile time Java type mismatch on @Transactional during compile time Jul 18, 2024
@edgar-espina-wpp
Copy link
Contributor

yea kotlin type system is bit harder, going to look.

Could anyone help me overcome with this error?

You could try to remove or comment the annotation for now, which makes all the routes transactional by default: https://jooby.io/modules/hibernate/#hibernate-transactional-request

@jknack jknack changed the title Java type mismatch on @Transactional during compile time kotlin: Java type mismatch on @Transactional during compile time Jul 18, 2024
@jonaskahn
Copy link
Author

Yeah, I changed to global transaction for all request by default. But it would be great to control the transaction in specific cases. ^^

@jknack jknack added this to the 3.2.6 milestone Jul 20, 2024
@jknack jknack closed this as completed in 5591578 Jul 20, 2024
jknack added a commit that referenced this issue Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants