7.2.1: schema validation fails for not-null database field mapped with @CreationTimestamp/@UpdateTimestamp

DB schema:

created_date timestamp with time zone not null default now(),
updated_date timestamp with time zone not null default now(),

Mapping:

@Column(updatable = false)
@CreationTimestamp
private OffsetDateTime createdDate;

@UpdateTimestamp
private OffsetDateTime updatedDate;

This works in 7.2.0.

With 7.2.1 it fails with (due to the change introduced in Jira):

Schema validation: column defined as not-null in the database, but nullable in model - [updated_date] in table [...]

Adding @NotNull to the mapping does not work either, as validation happen before the timestamps are generated.

What is the intended way to map not null db field with @CreationTimestamp/@UpdateTimestamp in 7.2.1? Or is it just a bug?

Using nullable = false works, it’s rather @NotNull cannot be used in such case:

    @Column(updatable = false, nullable = false)
    @CreationTimestamp
    private OffsetDateTime createdDate;

    @Column(nullable = false)
    @UpdateTimestamp
    private OffsetDateTime updatedDate;

Correct, @NotNull from the Jakarta Validation specification is a constraint that is validated on the Java object and when you pass an entity to persist, it obviously does not have a value set, since that will be generated. So the Jakarta Validation error would be inevitable, though I agree that this is a bit unfortunate. Can you please create a new Jira ticket for this i.e. Jakarta Validation error for @NonNull to be non-sensical with generators? Either we have to skip validating attributes that have generators or throw a boot error to notify users.

@beikov thanks for the response, this makes sense. I tried logging a ticket at Jira , but Create button just does nothing. It seems like something about Atlassian authentication, bunch of 401/400 errors in console, even though I am logged in, tried in different browser/account, same story - Create button does not do anything.

Thanks for reporting the problem. We recently figured out that most of the problems come when you authenticate via an external SSO provider. Also see the discussion in our chat: #hibernate-user > Jira issue creation

It seems you must “join” the Hibernate Jira first. There should be a “Log In” Button in the Account-Popup (where it has links to Profile and Account Settings). After clicking it, you should be prompted to join Hibernate’s Jira.

Alright, clicking account icon → Login does help. Another annoying thing is that the banner is displayed only after you do that :slight_smile: . While you are authenticated, but before clicking that another Login thing, the banner is not displayed :slight_smile: .

Anyways, while I was writing a ticket, I checked the sources again and found that this not-null schema validation was reverted altogether, and is not present in 7.2.2 anymore :slight_smile:. @beikov if you like I can still log a ticket, but I don’t see much value in it anymore, as 7.2.2 behaves exactly as I would want it to, i.e. “treat generated fields as not nullable for schema validation purposes“ or just “do not perform not-null schema validation on generated fields“.

It would still be useful to understand if a generator returns nullable values or not and do something with that information, like warn users.

@beikov sure. Created this one: Jira, please reword/change as necessary.