Skip to content

Instantly share code, notes, and snippets.

@mchlstckl mchlstckl/Property.kt
Last active Dec 12, 2019

Embed
What would you like to do?
Example entity with composite key Spring Boot and Kotlin
// This will not serialize!
data class Muppet(val name: String)
// This will serialize!
data class Puppet(val name: String = "")
// Composite key class must implement Serializable
// and have defaults.
class PropertyId(
val uuid: UUID = UUID.randomUUID(),
val name: String = "") : Serializable
// Need defaults everywhere!
@Entity
@IdClass(PropertyId::class)
data class Property(
@Id val uuid: UUID = UUID.randomUUID(),
@Id val name: String = "",
val value: String = "")
@johnacliffe

This comment has been minimized.

Copy link

johnacliffe commented Jul 25, 2019

Thank you, this was very helpful. Glad I found dug to the 2nd page of google and found this.

@binakot

This comment has been minimized.

Copy link

binakot commented Jul 31, 2019

Works like a charm 🍸
Thank you :octocat:

@mineralf

This comment has been minimized.

Copy link

mineralf commented Dec 12, 2019

I almost did set all those awful default values like in your example - but then I found the official Kotlin Docs recommending the JPA compiler plugin which generates the no-arg constructors for you! I think THAT is the way to go and worked perfectly fine for me: https://kotlinlang.org/docs/reference/compiler-plugins.html#jpa-support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.