hi,
Now I'm wondering what function the optional attributes in the @Column annotation have. I always thought it was the first place to "throw an exception" if for example the length=xyz attribute for a String field is exceeded. But when I try to persist a pojo with a mapped field like this, nothing happens. The only exceptions that gets thrown is a org.postgresql.util.PSQLException. And that is (if I'm correct) the exception thrown by the database length contrain...
I had the same problem with the nullable=false/true attribute. Only database exceptions... no hibernate ones. I then applied the nullable=false to another field (which is nullable in the database) and all of a sudden: A hibernate exception. After that, this nullable attribute works as I expected. Even on the fields that are NOT NULL in the database. No matter what constallation (nullable in code / NOT NULL in database etc...) now: Hibernate is the first to point out Constraint violations defined via field annotations.
But no such luck with the length attribute yet... or am I completely wrong, and this attribute is not supposed to check possible constraint violations before committing to the database?
Any insight would be appriciated.
TL;DR Hibernate watches out for nullable violations but nor for length ones
|