I use wildfly 37 with Hibernate 6.6.19.Final.
I have an embeddable object to store price values, either in cash or in percentage (for a financial Bond for example). An empty currency means a price in percent.
@Embeddable
public class PriceStrData implements Serializable {
@NotNull
@Column(name="amount")
private Double amount;
@Column(name="currency")
@Convert(converter = CurrencyEmptyConverter.class)
private Currency currency;
}
And the currency converter:
@Converter
public class CurrencyEmptyConverter implements AttributeConverter<Currency, String> {
@Override
public String convertToDatabaseColumn(Currency currency) {
return currency == null ? "" : currency.getCurrencyCode();
}
}
And my entity has:
@Embedded
@AttributeOverride(name = "amount", column = @Column(name="clean_unit_price_value"))
@AttributeOverride(name = "currency", column = @Column(name="clean_unit_price_currency", length=3))
private PriceStrData cleanUnitPrice;
The problem is : if cleanUnitPrice is null then the currency converter is called and the clean_unit_price_currency column contains an empty string and the clean_unit_price_value is null.
This is very strange as I expected both columns null if cleanUnitPrice is null. That is, no conversion should be applied for a null value.
So is it “normal” to call the converter if the embedded value is null ?
Is it a bug ?