https://kotlinlang.org logo
Join SlackCommunities
Powered by
# hibernate
  • s

    s1m0nw1

    08/10/2018, 5:56 AM
    Does anyone successfully use Hibernate with Kotlin? I'm currently looking for best practices as to how an
    Entity
    should be defined. It seems a good idea to just use
    data
    classes. That's probably not the best thing to do though as properties (esp. auto-generated ID) change after an entity has been persisted, which makes the Kotlin-generated equals/hashcode functions yield other results (this is a problem in hashed collections e.g.). Read here: https://stackoverflow.com/questions/1638723/how-should-equals-and-hashcode-be-implemented-when-using-jpa-and-hibernate
    m
    • 2
    • 2
  • a

    Alexjok

    11/13/2018, 9:22 AM
    Hello all! I want to link two tables across the bridge to the third table. In the bridge table, have a column with the condition (1, 2). And further, when deleting from the first table for example, information from the third table would be deleted too, where condition 1 in the bridge table. Its possible one bridge for two tables? And yeah, i use Kotlin 😛
    -.txt
  • m

    mariofelesdossantosjr

    01/24/2019, 12:19 PM
    Hello, does anyone have any examples with TornadoFX, Hibernate and ViewModel?
  • s

    Stian N

    04/05/2020, 6:25 PM
    Is this article outdated? https://kotlinexpertise.com/hibernate-with-kotlin-spring-boot/ I found this article that was updated a couple of months ago, and it doesn't mention any if the issues from the first article. https://www.baeldung.com/kotlin-jpa
  • d

    David Kubecka

    01/17/2023, 12:54 PM
    I'm having a weird issue with Hibernate. Not sure whether it's Kotlin specific but it seems to be quite generic so I guess Java guys would already complain 🙂 I have this in my
    BaseEntity
    (from which all other non-embeddable entities in my model inherit):
    Copy code
    @Id
        @GeneratedValue
        var id: Long? = null
    A framework I'm currently integrating would benefit from having the annotations on the getters instead of fields so I did this:
    Copy code
    @get:Id
        @get:GeneratedValue
        var id: Long? = null
    Once I do that (and only that) I run into really weird Hibernate errors on the app startup, e.g.
    Could not locate setter method for property [com.vacuumlabs.robo.backend.entities.Money#amount]
    . Well,
    Money#amount
    is indeed just a
    val
    but how is that related to moving the
    @Id
    annotation to the getter? Moreover,
    Money
    is exactly an embeddable entity that does not inherit from
    BaseEntity
    ... Okay, so I switch it to
    var
    and I get another error (from complete different entity):
    Unable to create unique key constraint (client_id, iban) on table account: database column 'client_id' not found
    . But of course the
    client_id
    column is there and if I switch the
    @Id
    back to the property annotation then my app starts and runs ok. I'm afraid I might be running into some generic issue here. Did anyone else encounter this?
    👍 1
    d
    • 2
    • 2
  • y

    Youssef Habri

    11/03/2023, 7:42 AM
    Hello, I'currently trying to used Kotlin with Hibernate, and I've found one weird issue with a certain feature of Hibernate. Hibernate has a multi-tenancy feature, and while trying it out, I had an issue with function overrides from the
    MultiTenantConnectionProvider
    interface. The issue I'm having is with
    isUnwrappableAs
    and
    unwrap
    functions:
    Copy code
    class TenantSchemaConnectionProvider : MultiTenantConnectionProvider {
        override fun isUnwrappableAs(unwrapType: Class): Boolean {
            TODO("Not yet implemented")
        }
    
        override fun <T : Any?> unwrap(unwrapType: Class): T {
            TODO("Not yet implemented")
        }
    
        // the rest of the overrides
    }
    In this case, the compiler complains with the following error:
    One type argument expected for class Class<T : Any!>
    . I've tried changing the types to
    Class<*>
    and
    Class<T>
    respectively, but that just makes the compiler complain the the functions are not overriding anything, and that the class has missing overrides from the interface. Any idea how to solve this issue?
  • y

    Youssef Habri

    11/03/2023, 7:52 AM
    Ok, the issue does get solved if do:
    Copy code
    class TenantSchemaConnectionProvider : MultiTenantConnectionProvider {    
        override fun isUnwrappableAs(@NotNull unwrapType: Class<*>): Boolean {
            return false
        }
    
        override fun <T> unwrap(@NotNull unwrapType: Class<T>): T? {
            return null
        }
        // ...
    }
    But, the IDE still complains that it's wrong. The compiler accepts it tho 🤔
  • y

    Youssef Habri

    11/03/2023, 7:54 AM
    I guess this is more of an issue with the Kotlin IDE plugin, I guess I should post this in the relevant channel?