Improvement suggestion: Error message when Embeddable has a missing field
Opened this issue · 0 comments
Issue description
Hi there!
I would like to suggest an improvement on how Micronaut Data handles error messages for the following use case.
When using a validated @Embeddable
, if:
- It has a mandatory field
- The result set has a null value for that field
The error message is a bit confusing, as it says that the whole @Embeddable
is null/missing. Take for example these data models:
@MappedEntity("my_entity")
public record MyEntity(
@MappedProperty("id") @Id @GeneratedValue @Nullable Long id,
@Relation(Relation.Kind.EMBEDDED) @Valid @NotNull AuditFields auditFields) {
}
@Embeddable
public record AuditFields(
@MappedProperty("created_on") @NotNull LocalDate createdOn,
@MappedProperty("created_by") @NotBlank String createdBy) {
}
If the DB has a missing/null createdBy
field, for instance, this is the error message throw by the repository:
Error instantiating entity [io.github.nahuel92.MyEntity]: Null argument specified for [auditFields]. If this argument is allowed to be null annotate it with @Nullable
This can be improved by making the error message something like this:
Error instantiating entity [io.github.nahuel92.MyEntity]: Null argument specified for [auditFields.createdBy]. If this argument is allowed to be null annotate it with @Nullable
Here's an example app where you can see this in action:
Thanks!