hibernate/hibernate-orm · error · IllegalStateException

no unique value

Error message

no unique value

What it means

MetaAttribute#getValue throws IllegalStateException when the attribute holds zero or more than one value - only a single-valued meta attribute has a unique value. Meta attributes come from hbm <meta value="..."> elements and may legitimately repeat, so asking for 'the' value is only valid when exactly one exists.

Solutions

  1. Call isMultiValued() or check getValues().size() before getValue(), or just use getValues() when multiple values are legal.
  2. Deduplicate the <meta> elements in the hbm file so the attribute is single-valued.
  3. Update tooling that assumes uniqueness to handle the value list.

Example fix

// before
String v = metaAttribute.getValue(); // throws when 0 or 2+ values

// after
if (metaAttribute.getValues().size() == 1) {
    String v = metaAttribute.getValue();
} else {
    List<String> all = metaAttribute.getValues();
}
Defensive patterns

Strategy: type-guard

Type guard

static Optional<String> uniqueValue(MetaAttribute attr) {
    return attr.getValues().size() == 1
            ? Optional.of(attr.getValue())
            : Optional.empty();
}

Prevention

When it happens

Trigger: The same <meta attribute="..."> declared multiple times in one mapping element; inheritable meta attributes duplicated across mapping levels; tooling (hbm2java, reverse engineering) reading a single value from a multi-valued attribute; calling getValue() without checking the value count.

Common situations: Hand-edited hbm files where meta tags were duplicated by copy-paste; templates emitting the same meta attribute more than once; merging mappings that each carry the same meta attribute.

Related errors


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/mapping/MetaAttribute.java:38

	public MetaAttribute(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public java.util.List<String> getValues() {
		return Collections.unmodifiableList(values);
	}

	public void addValue(String value) {
		values.add(value);
	}

	public String getValue() {
		if ( values.size()!=1 ) {
			throw new IllegalStateException("no unique value");
		}
		return values.get(0);
	}

	public boolean isMultiValued() {
		return values.size()>1;
	}

	public String toString() {
		return "[" + name + "=" + values + "]";
	}
}

View on GitHub (pinned to fad1729dce)