@Embeddable with @CollectionTable field always non-null even if no data in joined table

When using @CollectionTableCollectionTable in nullable @Embedded, entity always got not-null reference even if no data. Example project to reproduce issue, contains problem entity:

When row in db contains only id and no data in joined columns expecting that data field should be null, but instead it contains not valid object

Expected :null
Actual :AddressCollection(addressString=null, fields=)

How can I change this behavior? Is it possible to use a converter, but then what types should I specify to make it work?

JDK 21
Spring Boot 3.5.6
Hibernate 6.6.29.Final

Hello @Anton_Ram, I don’t think there’s a way to do this with @ElementCollection, as Hibernate has no way of distinguishing between a null association and an empty collection when there’s no record in the collection table.

Why do you need to make this distinction in the first place?

You could use @JdbcTypeCode(SqlTypes.JSON) val fields: List<AddressMetadata> to store the data as JSON.

To rich event consistency. We can receive link to object before real data and create “empty” entity with only id. When real data received we will enrich created entity, but this topic now has no meaning as this feature is deprecated as i see