hibernate/hibernate-orm · error · MappingException

idbag mapping missing @CollectionId

Error message

idbag mapping missing @CollectionId

What it means

Error "idbag mapping missing @CollectionId" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java:402

				break;
			case LIST_INDEX:
				prepareListIndex( value );
				break;
			case MAP_KEY:
				prepareMapKey( value, typeDetails );
				break;
			case COLLECTION_ELEMENT:
				prepareCollectionElement( value, typeDetails );
				break;
			default:
				throw new IllegalArgumentException( "Unexpected binder type : " + kind );
		}
	}

	private void prepareCollectionId(MemberDetails attribute) {
		final var collectionId = attribute.getDirectAnnotationUsage( CollectionId.class );
		if ( collectionId == null ) {
			throw new MappingException( "idbag mapping missing @CollectionId" );
		}

		final boolean useDeferredBeanContainerAccess = useDeferredBeanContainerAccess();
		final var beanRegistry = getManagedBeanRegistry();

		implicitJavaTypeAccess = typeConfiguration -> null;

		final var modelContext = getSourceModelContext();

		explicitJavaTypeAccess = typeConfiguration -> {
			final var idJavaClass = attribute.locateAnnotationUsage( CollectionIdJavaClass.class, modelContext );
			if ( idJavaClass != null ) {
				return (BasicJavaType<?>)
						buildingContext.getBootstrapContext().getTypeConfiguration()
								.getJavaTypeRegistry().resolveDescriptor( idJavaClass.idType() );
			}
			final var idJavaType = attribute.locateAnnotationUsage( CollectionIdJavaType.class, modelContext );
			if ( idJavaType != null ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add a @CollectionId annotation to the idbag collection mapping.
  2. Or change the collection mapping from idbag to a bag or list mapping that does not require @CollectionId.

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