Found the solution!
It’s obvious now, but the problem was that I was using JPA field annotation instead of accessor. It all made sense after having a look at the bytecode that Kotlin was generating for the TestMixin
class.
This is the updated solution:
interface TestTrait {
@get:Column
var traitValue: Int
}
class TestTraitImpl : TestTrait {
override var traitValue: Int = 0
}
@MappedSuperclass
class TestMixin :
TestTrait by TestTraitImpl() {
@get:Column
var mixinValue: Int = 0
}
@Entity
@Table
public class TestEntity extends TestMixin {
private UUID id;
private int entityValue;
@Id
@GeneratedValue
@Type(type = "uuid-char")
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
@Column
public int getEntityValue() {
return entityValue;
}
public void setEntityValue(int entityValue) {
this.entityValue = entityValue;
}
}
I always preferred field annotation over accessor, but being able to use composition on my JPA entities is much more important!