Skip to content

Embedded entities can not be constructed when they use Kotlin val properties #1677

@koenpunt

Description

@koenpunt

To retrieve results indexed by a specific column (relation_id), we use "pair" classes. For example;

// Repository method
@Query(
    """
        SELECT o.id AS relation_id, c.* FROM customer_details c
        JOIN orders o ON o.customer_details_id = c.id
        WHERE o.id IN (:ids)
    """
)
suspend fun findAllByOrderIdIn(ids: Iterable<UUID>): List<CustomerDetailsPair>

// ...

// The virtual pair entity
data class CustomerDetailsPair(
    override val relationId: UUID,
    @Embedded.Empty
    override val entity: CustomerDetails,
)

// The CustomerDetails entity
@Table(name = "customer_details")
class CustomerDetails(
    val name: String,
    var email: String?,
)

But this results in the following exception being thrown:

Cannot set property name because no setter, no wither and it's not part of the persistence constructor public oopen.timemachine.entities.CustomerDetails(java.lang.String,java.lang.String)

When changing the name property to a var, no error is thrown. The entity as a standalone entity, so not embedded, can be constructed without changing the property to a var.

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions