softshipper
softshipper

Reputation: 34099

org.hibernate.MappingException: Composite-id class must implement Serializable: StoreEntity

I try to use Hibernate in Quarkus with Kotlin.
The entity definition looks as follows:

import io.quarkus.hibernate.reactive.panache.PanacheEntity
import io.quarkus.runtime.annotations.RegisterForReflection
import javax.persistence.EmbeddedId
import javax.persistence.Entity

@Entity
@RegisterForReflection
open class StoreEntity(
    @EmbeddedId
    var userId: UserId,
    var password: String,
    var createdAt: Long
) : PanacheEntity()

and the composite key:

import io.quarkus.runtime.annotations.RegisterForReflection
import java.io.Serializable
import javax.persistence.Embeddable

@Embeddable
@RegisterForReflection
open class UserId(
    var id: String
) : Serializable

Unfortunately the compiler complains:

Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(Unknown Source)
        ... 17 more
Caused by: org.hibernate.MappingException: Composite-id class must implement Serializable: StoreEntity
        at org.hibernate.mapping.RootClass.checkCompositeIdentifier(RootClass.java:293)
        at org.hibernate.mapping.RootClass.validate(RootClass.java:276)
        at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:359)
        at io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata.validateAndWrap(PrevalidatedQuarkusMetadata.java:58)

As you can see the Serializable interface is implemented in the composite keys.

What am I doing wrong?

The project is hosted on https://github.com/softshipper/kibernate

Upvotes: 0

Views: 361

Answers (1)

Davide D&#39;Alto
Davide D&#39;Alto

Reputation: 8236

I think the problem is that StoreEntity must be Serializable too. That's what the exception is saying.

Upvotes: 1

Related Questions