Just talking about simple id, even if we allow the column to be nullable
(if the DB even allows that), I don't think Hibernate allows null to be
a valid id value. Because null means I don't know or not applicable.
I think in the past we argued the same for attributes of a composite id,
like you said, if one of the element can be nul, why is it in the id
property in the first place.
As for whether there is a strong implementation detail reason to not
allow it, I don't know but I assume the null checking assuming "not an
id" is pretty much all over the place.
On 11 Dec 2019, at 3:37, Gail Badner wrote:
Currently, there is no way to load an entity that exists in the
with a composite ID, if one of the composite ID columns is null.
This behavior is due to this code in ComponentType#hydrate:
Basically, if any field/property in a composite ID is null, Hibernate
assumes the entire ID is null. An entity cannot have a null ID, so it
returns null for the entity result.
I believe that Hibernate does allow a primary key column to be
TBH, it seems strange to have a property in a composite ID that can be
null. If it can be null, it seems that the property could be removed
the composite key.
I don't see anything in the spec about a requirement that all
fields/properties must be non-null. Am I missing something?
The code I referenced above is 13 years old. Does anyone have insight
why Hibernate does this?
hibernate-dev mailing list