https://kotlinlang.org logo
Join SlackCommunities
Powered by
# jpa
  • m

    Marcel Overdijk

    11/26/2018, 8:33 PM
    I don't know if this channel is actively used, but let's try.
  • m

    Marcel Overdijk

    11/26/2018, 8:34 PM
    I'm facing an issue where Kotlin JPA classes are behaving unexpected and different than the Java likes.
  • m

    Marcel Overdijk

    11/26/2018, 8:35 PM
    It has to do with proxies and @Id columns of associations
  • m

    Marcel Overdijk

    11/26/2018, 8:36 PM
    E.g. when having a
    Country
    association
    Continent
    like:
  • m

    Marcel Overdijk

    11/26/2018, 8:37 PM
    Copy code
    @Entity
    class Country(
            @Id
            var id: String,
            var alpha2Code: String,
            var alpha3Code: String,
            var name: String,
            @ManyToOne(fetch = FetchType.LAZY)
            @JoinColumn(name = "continent_id")
            var continent: Continent
    )
  • m

    Marcel Overdijk

    11/26/2018, 8:37 PM
    (note the association is lazy)
  • m

    Marcel Overdijk

    11/26/2018, 8:37 PM
    you could dome something like:
  • m

    Marcel Overdijk

    11/26/2018, 8:38 PM
    Copy code
    val country = countryRepository.findById("netherlands").get()
    assertEquals("europe", country.continent.id)
  • m

    Marcel Overdijk

    11/26/2018, 8:39 PM
    now, this call to
    country.continent.id
    should not cause the continent to be fetched, but with above Kotlin it is (causing additional query).
  • m

    Marcel Overdijk

    11/26/2018, 8:40 PM
    the Java equivalent (or what comes close to it) is not doing the additional continent query.
  • m

    Marcel Overdijk

    11/26/2018, 8:43 PM
    See also SO discussion: https://stackoverflow.com/questions/53466913/how-to-avoid-initializing-a-hibernate-proxy-when-only-the-entity-id-is-needed
  • m

    Marcel Overdijk

    11/26/2018, 8:43 PM
    and a sample project (with Kotlin and Java) I created: https://github.com/marceloverdijk/hibernate-proxy-id
  • m

    Marcel Overdijk

    11/26/2018, 8:45 PM
    Does somebody know this could be related to the Kotlin generated bytecode and/or the Kotlin JPA compiler plugin?
  • m

    Marcel Overdijk

    11/29/2018, 7:32 AM
    Note I have created https://youtrack.jetbrains.net/issue/KT-28525 for this.
  • x

    xenoterracide

    03/18/2019, 5:19 PM
    anyone know how to do this? https://stackoverflow.com/q/55226704/206466
  • j

    Jeff White

    04/11/2019, 6:42 PM
    Are most people using non-data classes, and var instead of vals for their Entities?
    x
    • 2
    • 2
  • d

    Dave Jensen

    12/18/2019, 7:21 PM
    🤔 I posted a question in #spring regarding delegates to build entities; maybe I should've posted it here?
  • t

    Tim Schraepen

    11/25/2021, 9:48 AM
    Hey y’all. Anyone know if you can use
    value class
    as an
    @Id
    field? First our integration test was complaining that the class wasn’t Serializable (on save), after we fixed that we got an error on retrieval saying something about an Invalid Type.
  • t

    Tim Schraepen

    12/06/2021, 4:39 PM
    🦗
    😀 2
  • a

    Aaron Shakib

    02/07/2023, 2:18 AM
    hello K peeps!
  • a

    Aaron Shakib

    02/07/2023, 2:19 AM
    OOC - is there any easy way to combine Flyway and JPA to manage generated migrations
    • 1
    • 1