Skip to content

Instantly share code, notes, and snippets.

@mchlstckl
Last active August 4, 2023 07:37
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchlstckl/4f9602b5d776878f48f0 to your computer and use it in GitHub Desktop.
Save mchlstckl/4f9602b5d776878f48f0 to your computer and use it in GitHub Desktop.
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 = "")
@valerymarkov
Copy link

Thanks a lot for pointing to @IdClass and @Id annotations!
I tried using @EmbeddedId first and couldn't get rid of "org.springframework.orm.jpa.JpaSystemException: Could not set field value [] value by reflection : " error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment