Hibernate Envers implementation of custom composite type

60 views Asked by At

I'm trying to audit my custom Postgres type with Hibernate Envers, also I'm using Quarkus with Kotlin and panache repository.

My Postgres setup:

CREATE TYPE money_and_currency AS (amount integer, currency varchar(3));
CREATE TABLE example_table (
    "id" uuid,
    "maximum_value" money_and_currency,
    "minimum_value" money_and_currency
);

My Entity setup:

@Table(name = "example_table")
@Entity
@Audited
class ExpectedPaymentEntity {
    @Id
    @GeneratedValue
    @Column(columnDefinition = "uuid", updatable = false)

    @Column(name = "maximum_value")
    @Embedded
    var maximumValue: MoneyAndCurrency ?= null

    @Column(name = "minimum_value")
    @Embedded
    var minimumValue: MoneyAndCurrency ?= null
}

@Embeddable
@Struct(name = "money_and_currency")
class MoneyAndCurrency(
    val amount: Int,
    val currency: String
)

I got this error when trying to compile my project:

Column 'amount' is duplicated in mapping for entity 'project.transaction.adapter.out.hibernate.entity.ExpectedPaymentEntity_AUD' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)

I tried adding this line to my entity and indeed the code compiles, but nothing is audited when I run my db operations. I want to audit these two fields in the way they are persisted

0

There are 0 answers