hibernate/hibernate-orm · error · MappingException
idbag mapping missing '@CollectionId' annotation
Error message
idbag mapping missing '@CollectionId' annotation
What it means
Error "idbag mapping missing '@CollectionId' annotation" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java:53
public IdBagBinder(
Supplier<ManagedBean<? extends UserCollectionType>> customTypeBeanResolver,
MetadataBuildingContext buildingContext) {
super( customTypeBeanResolver, buildingContext );
}
@Override
protected Collection createCollection(PersistentClass owner) {
return new IdentifierBag( getCustomTypeBeanResolver(), owner, getBuildingContext() );
}
@Override
protected boolean bindStarToManySecondPass(Map<String, PersistentClass> persistentClasses) {
final boolean result = super.bindStarToManySecondPass( persistentClasses );
final var collectionIdAnn = property.getDirectAnnotationUsage( CollectionId.class );
if ( collectionIdAnn == null ) {
throw new MappingException( "idbag mapping missing '@CollectionId' annotation" );
}
final var propertyData = new WrappedInferredData(
new PropertyInferredData(
null,
declaringClass,
property,
//default access should not be useful
null,
buildingContext
),
"id"
);
final var idColumns = AnnotatedColumn.buildColumnsFromAnnotations(
new Column[]{collectionIdAnn.column()},
// null,
null,View on GitHub (pinned to fad1729dce)
Solutions
- Add @CollectionId to the idbag collection mapping, or change the mapping type.
When it happens
Trigger: An identifier/value generator declaration is inconsistent with the referenced generator or the annotated element.
Common situations: @GeneratedValue pointing at a generator of the wrong kind (SEQUENCE vs TABLE), a missing named generator, too many generator annotations, or an unsupported generation strategy for @CollectionId.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/47f229ec57a1d801.
Report an issue: GitHub.