hibernate/hibernate-orm · error · PropertyAccessException

Null value was assigned to a property

Error message

Null value was assigned to a property [%s.%s] of primitive type

What it means

Reflection guard in field-based property setting: Field.set threw (typically NullPointerException unboxing) while assigning null to a property whose Java type is primitive, which cannot hold null. The faulty input is the null value being written to the primitive property; make the property a wrapper type or avoid writing null.

Solutions

  1. Change the primitive field to its wrapper type (e.g. Integer instead of int) if null is valid.
  2. Ensure the database column is NOT NULL or provide a default value.
Defensive patterns

Strategy: validation

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/fa4c658791a75390. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java:57

		return containerClass;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public Field getField() {
		return field;
	}

	@Override
	public void set(Object target, @Nullable Object value) {
		try {
			field.set( target, value );
		}
		catch (Exception e) {
			if ( value == null && field.getType().isPrimitive() ) {
				throw new PropertyAccessException(
						e,
						String.format(
								Locale.ROOT,
								"Null value was assigned to a property [%s.%s] of primitive type",
								containerClass,
								propertyName
						),
						true,
						containerClass,
						propertyName
				);
			}
			else {
				throw new PropertyAccessException(
						e,
						String.format(
								Locale.ROOT,
								"Could not set value of type [%s]",

View on GitHub (pinned to fad1729dce)