Hey,
I have a Spring project (Hibernate 6.6) with database schema validation enabled with spring.jpa.hibernate.ddl-auto=validate
. I have a simple test entity:
@Entity
public class TestEntity {
@Id int id;
int number;
// Getters & setters...
}
And my schema is as follows with some test data:
CREATE TABLE test_entity (
id INT PRIMARY KEY NOT NULL,
number INT
);
INSERT INTO test_entity VALUES (1, 1);
INSERT INTO test_entity VALUES (2, NULL);
Hibernate validation passes even though number
is a primitive field that maps to a nullable column. When annotating the field with @Column(nullable = false)
validation still passes.
Perhaps I’m missing something or is this a missing feature? I would find primitive ↔ nullable validation very useful so it’s more difficult to create footguns (ask me how I know ). Feels especially strange since letting Hibernate create the table with spring.jpa.hibernate.ddl-auto=create
sets the number
column as non-nullable.
Apologies if this has been discussed before, I couldn’t find information about this particular topic.