hibernate/hibernate-orm · error · MappingException

Duplicate property mapping of " + property.getName() + " fou

Error message

Duplicate property mapping of " + property.getName() + " found in " + getEntityName()

What it means

Two properties with the same name were added to one entity's property list. checkPropertyDuplication() runs during validate() and rejects the mapping because Hibernate binds property names to fields/getters uniquely. Typical causes are a subclass re-declaring an inherited property, or merged mappings defining the same property twice.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java:718

				final int actualColumns = prop.getColumnSpan();
				final int requiredColumns = type.getColumnSpan( mapping );
				throw new MappingException(
						"Property '" + qualify( getEntityName(), prop.getName() )
								+ "' maps to " + actualColumns + " columns but " + requiredColumns
								+ " columns are required (type '" + type.getName()
								+ "' spans " + requiredColumns + " columns)"
				);
			}
		}
		checkPropertyDuplication();
		checkColumnDuplication();
	}

	private void checkPropertyDuplication() throws MappingException {
		final HashSet<String> names = new HashSet<>();
		for ( var property : getProperties() ) {
			if ( !names.add( property.getName() ) ) {
				throw new MappingException( "Duplicate property mapping of " + property.getName() + " found in " + getEntityName() );
			}
		}
	}

	public boolean isDiscriminatorValueNotNull() {
		return NOT_NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
	}

	public boolean isDiscriminatorValueNull() {
		return NULL_DISCRIMINATOR_MAPPING.equals( getDiscriminatorValue() );
	}

	public Map<String, MetaAttribute> getMetaAttributes() {
		return metaAttributes;
	}

	public void setMetaAttributes(java.util.Map<String,MetaAttribute> metas) {
		this.metaAttributes = metas;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Find the duplicate name from the message and remove or rename one of the two mappings
  2. For inherited state, rely on inheritance instead of re-declaring the field on the subclass
  3. When merging XML files, de-duplicate repeated property entries

Example fix

// before
class Base { private String name; }                 // mapped on root
@Entity class Sub extends Base { private String name; } // duplicate

// after
@Entity class Sub extends Base { private String subName; } // or drop the field entirely
Defensive patterns

Strategy: validation

Validate before calling

Set<String> names = new HashSet<>();
for (Property p : pc.getProperties()) {
    if (!names.add(p.getName())) {
        // duplicate property name: rename or remove one mapping before validation runs
    }
}

Try / catch

try { metadata.buildSessionFactory(); }
catch (MappingException e) {
    if (e.getMessage().contains("Duplicate property mapping")) {
        // the message names the property and entity; remove the second declaration
    }
    throw e;
}

Prevention

When it happens

Trigger: A subclass with @Entity re-declaring a field already mapped on its root or @MappedSuperclass; XML mappings where a property element with the same name appears twice after merging files; tooling resolving both an is-getter and a get-getter as separate properties.

Common situations: Copy-pasting fields from parent to subclass; IDE generating duplicate field and method mappings; merging hbm.xml fragments that both define the same property.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/5c2d5d72ae7c7534. Report an issue: GitHub.