hibernate/hibernate-orm · error · AnnotationException

Collection '<propertyName>' was annotated '@Collate'

Error message

Collection '<propertyName>' was annotated '@Collate'

What it means

CollateBinder throws for any Collection-typed value: an @ElementCollection, @ManyToMany, or @OneToMany maps to rows in a collection or target table rather than a simple column of the entity, and Hibernate 6.5+ declines to apply @Collate through such properties. The collation must be declared on the actual element/key columns.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/binder/internal/CollateBinder.java:32

import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;

/**
 * Handles {@link Collate} annotations.
 *
 * @author Gavin King
 */
public class CollateBinder implements AttributeBinder<Collate> {
	@Override
	public void bind(Collate collate, MetadataBuildingContext context, PersistentClass entity, Property property) {
		final Value value = property.getValue();
		if ( value instanceof OneToMany ) {
			throw new AnnotationException( "One to many association '" + property.getName()
					+ "' was annotated '@Collate'");
		}
		else if ( value instanceof Collection ) {
			throw new AnnotationException( "Collection '" + property.getName()
					+ "' was annotated '@Collate'");

		}
		else {
			for ( Column column : value.getColumns() ) {
				column.setCollation( collate.value() );
			}
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove @Collate from the collection property.
  2. Declare collation on the element/key column itself via @Column(columnDefinition = "varchar(255) collate ...") on the element mapping.
  3. Or set the collation at the database level (ALTER TABLE / default charset) for the collection table.

Example fix

// before
@ElementCollection
@Collate("und-x-icu")
@Column(name = "tag")
private List<String> tags;

// after
@ElementCollection
@Column(name = "tag", columnDefinition = "varchar(255) collate und-x-icu")
private List<String> tags;
Defensive patterns

Strategy: validation

Validate before calling

for (Field f : cls.getDeclaredFields()) {
    if (f.isAnnotationPresent(org.hibernate.annotations.Collate.class)
            && java.util.Collection.class.isAssignableFrom(f.getType())) {
        throw new IllegalStateException("@Collate not allowed on collection: " + f.getName());
    }
}

Try / catch

Catch org.hibernate.AnnotationException during SessionFactory build; the message identifies the collection property. Abort startup.

Prevention

When it happens

Trigger: @Collate on a collection property — typically @ElementCollection List<String> tags or @ManyToMany Set<Tag> — during attribute binding the value is a Collection and the binder throws.

Common situations: Applying database collation rules to tag/keyword element collections; global annotation sweeps that accidentally hit collection fields; schema reviews demanding collation on collection-table columns.

Related errors


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