This came up while looking into [https://github.com/quarkusio/quarkus/issues/33740|https://github.com/quarkusio/quarkus/issues/33740|smart-link]
When there’s an entity hierarchy that relies on the usage of overridden properties, a state built for a subtype ends up having nulls for such a property. For example, with a model
{noformat}@Entity @Table(name = "shape") @Inheritance(strategy = InheritanceType.JOINED) abstract class Shape(
@Id @JdbcTypeCode(SqlTypes.VARCHAR) @Column(name = "id", updatable = false, nullable = false, unique = true) open val id: UUID,
@Length(max = 100) @Column(name = "name", nullable = false, length = 100) open var name: String, )
@Entity @Table(name = "rectangle") @PrimaryKeyJoinColumn(name = "shape_id") data class Rectangle( override val id: UUID, override var name: String, ) : Shape(id, name) {noformat}
trying to persist a rectangle entity :
{noformat}val rectangle = Rectangle( id = UUID.randomUUID(), name = "Rectangle", color = Color.Red, properties = Properties("foo", "bar") )
em.persist(rectangle){noformat}
will result in [https://github.com/hibernate/hibernate-orm/blob/f22d7e1328c0e063528eb8a16ccaf6a064e8f713/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java#L325|https://github.com/hibernate/hibernate-orm/blob/f22d7e1328c0e063528eb8a16ccaf6a064e8f713/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java#L325|smart-link] returning an array of nulls and failing the operation.
Also, confirmed that switching to {{@Access(AccessType.PROPERTY)}} for such properties helps to work around the problem.
Note: issue does not affect 5.6 as, in the end – fields were accessed by a Feild form a subtype rather than a supertype. |
|