hibernate/hibernate-orm · error · PropertyAccessException
Null value was assigned to a property of primitive type
Error message
Null value was assigned to a property of primitive type
What it means
Error "Null value was assigned to a property of primitive type" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java:44
private final Method setterMethod;
private final boolean isPrimitive;
public SetterMethodImpl(Class<?> containerClass, String propertyName, Method setterMethod) {
this.containerClass = containerClass;
this.propertyName = propertyName;
this.setterMethod = setterMethod;
this.isPrimitive = setterMethod.getParameterTypes()[0].isPrimitive();
}
@Override
public void set(Object target, @Nullable Object value) {
try {
setterMethod.invoke( target, value );
}
catch (NullPointerException npe) {
if ( value == null && isPrimitive ) {
throw new PropertyAccessException(
npe,
"Null value was assigned to a property of primitive type",
true,
containerClass,
propertyName
);
}
else {
throw new PropertyAccessException(
npe,
"NullPointerException occurred while calling",
true,
containerClass,
propertyName
);
}
}
catch (InvocationTargetException ite) {View on GitHub (pinned to fad1729dce)
Solutions
- Use the wrapper type instead of a primitive if the property can be null.
- Make the column NOT NULL or supply a default.
When it happens
Trigger: Null is assigned to a primitive-typed persistent property.
Common situations: Loading a nullable database column into a primitive field, or explicitly setting null on a primitive property.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b0e88f903e0512ac.
Report an issue: GitHub.